From 434f6952c34414d59e06af4eefa11626d1919b6a Mon Sep 17 00:00:00 2001 From: Nick Palmer Date: Wed, 26 Aug 2020 12:46:36 -0500 Subject: [PATCH] Doc: Add Jest/Enzyme testing docs --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 6e05ee8..76957fa 100644 --- a/README.md +++ b/README.md @@ -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.