enzyme-adapter-react-16-with-shallow-effects
v1.1.0
Published
Shallow enzyme rendering with effect support
Downloads
5,454
Maintainers
Readme
enzyme-adapter-react-16-with-shallow-effects
This extremely-long-named package is a "fork" of the react-16 adapter included with enzyme, with one difference that applies only to shallow()
testing:
- useEffect and useLayoutEffect hooks are supported, with dependency change tracking and cleanup support. See this enzyme issue for more information.
Also, under the hood, it uses react-shallow-renderer
rather than react-test-renderer/shallow
. Ongoing development of react-test-renderer/shallow
has been moved to react-shallow-renderer
. This should not result in any observable differences in behavior.
Example Usage:
import React from 'react';
import { shallow, configure } from 'enzyme';
import AdapterWithShallowEffects from 'enzyme-adapter-react-16-with-shallow-effects';
// setup enzyme to use the adapter
configure({ adapter: new AdapterWithShallowEffects() });
const ExampleComponent = () => {
useEffect(() => {
console.log('effect triggered!);
return () => { console.log('effect cleaned up!); };
});
return <div />
};
console.log('rendering shallow');
const rendered = shallow(<ExampleComponent />)
console.log('unmounting');
shallow.unmount();
console.log('done');