Skip to content

Commit

Permalink
Doc: Add Jest/Enzyme testing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nickpalmer committed Aug 26, 2020
1 parent b57d1c2 commit 434f695
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 434f695

Please sign in to comment.