react-perimeter
react-perimeter copied to clipboard
Add test suite
It's probably hard to test the actual core feature of react-perimeter , but there are a few things we can definitely test:
- correctly exports the React component
- renders children
- attaches
refcorrectly with render callbacks - registers event listeners on mount
- removes event listeners on unmount
- removes event listeners after
onBreachis called ifonceistrue - more stuff
I'd like to use jest and enzyme for this.
@aweary If your okay with it, I would like to take a stab at it.
@binoy14 go for it! Feel free to ping me here with any questions
@aweary If you could help me with how to test event listeners that would be a big help I made initial commit here https://github.com/binoy14/react-perimeter/commit/7878a98caa8f126450f7401dc4dbce3d160c1bf6
@binoy14 I would probably mock window.addEventListener and window.removeEventListener and then assert that they've been called at the correct point and the correct number of times
See Jest's doc page on mocks: https://facebook.github.io/jest/docs/mock-functions.html
We can do this in the beforeEach hook, so the mock is reset before each test:
beforeEach(() => {
window.addEventListener = jest.fn()
window.removeEventListener = jest.fn()
})
The doc page I linked has some info on how to assert on mocked functions in Jest.