-
Notifications
You must be signed in to change notification settings - Fork 429
/
Copy pathenzyme-helpers.js
37 lines (30 loc) · 1.03 KB
/
enzyme-helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { configure, mount } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
configure({ adapter: new Adapter() });
/*
Setup and takedown
*/
function createMountNode({ context, mountNodeId }) {
const internalmountNodeId = mountNodeId || 'mount-node';
// eslint-disable-next-line no-param-reassign
context.dom = document.createElement('div');
const mountNode = document.body.appendChild(context.dom);
mountNode.id = internalmountNodeId;
return mountNode;
}
const mountComponent = (instance) =>
function mountComponentInside() {
this.dom = document.createElement('div');
const mountNode = document.body.appendChild(this.dom);
mountNode.id = 'mount-node';
this.wrapper = mount(instance, { attachTo: mountNode });
};
function unmountComponent() {
this.wrapper.unmount();
document.body.removeChild(this.dom);
}
function destroyMountNode({ wrapper, mountNode }) {
wrapper.unmount();
document.body.removeChild(mountNode);
}
export { createMountNode, destroyMountNode, mountComponent, unmountComponent };