Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test suite #5

Open
aweary opened this issue Mar 17, 2017 · 4 comments
Open

Add test suite #5

aweary opened this issue Mar 17, 2017 · 4 comments

Comments

@aweary
Copy link
Owner

aweary commented Mar 17, 2017

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 ref correctly with render callbacks
  • registers event listeners on mount
  • removes event listeners on unmount
  • removes event listeners after onBreach is called if once is true
  • more stuff

I'd like to use jest and enzyme for this.

@binoy14
Copy link
Contributor

binoy14 commented Mar 18, 2017

@aweary If your okay with it, I would like to take a stab at it.

@aweary
Copy link
Owner Author

aweary commented Mar 18, 2017

@binoy14 go for it! Feel free to ping me here with any questions

@binoy14
Copy link
Contributor

binoy14 commented Mar 18, 2017

@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

@aweary
Copy link
Owner Author

aweary commented Mar 18, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants