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

Doc: Add Jest/Enzyme testing docs #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,23 @@ module.exports = {
}
```

## Jest and Enzyme testing with this library

In order to test code using this library with Jest and Enzyme, you need to mock the library to return
a standard lazy promise. Enzyme doesn't understand how to handle the component returned by this library.

You can bypass this by adding the following to your `jestsetup.js`

```
// Convert react-lazy-ssr to regular lazy for enzyme to be able to handle it
jest.mock('react-lazy-ssr', () => {
return jest.fn().mockImplementation((load, config) => {
const lazy = require('react').lazy;
return lazy(load);
});
});
```

## Tests

Use `npm test` to run the tests. Use `npm run cover` to check coverage.
Expand Down