piral-core 0.15.0-alpha.4345 → 0.15.0-alpha.4399

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,6 @@ import { ExtensionSlot, SwitchErrorInfo } from '../components';
5
5
  * Leverage the default one by registration of respective extensions using
6
6
  * the "error" name.
7
7
  */
8
- export const DefaultErrorInfo = (props) => (React.createElement(ExtensionSlot, { name: "error", params: props, empty: () => React.createElement(SwitchErrorInfo, Object.assign({ key: "default_error" }, props)) }));
8
+ export const DefaultErrorInfo = (props) => (React.createElement(ExtensionSlot, { name: "error", params: props, empty: () => React.createElement(SwitchErrorInfo, Object.assign({}, props)) }));
9
9
  DefaultErrorInfo.displayName = 'DefaultErrorInfo';
10
10
  //# sourceMappingURL=DefaultErrorInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultErrorInfo.js","sourceRoot":"","sources":["../../src/defaults/DefaultErrorInfo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA6B,CAAC,KAAK,EAAE,EAAE,CAAC,CACnE,oBAAC,aAAa,IAAC,IAAI,EAAC,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,oBAAC,eAAe,kBAAC,GAAG,EAAC,eAAe,IAAK,KAAK,EAAI,GAAI,CAC/G,CAAC;AACF,gBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC"}
1
+ {"version":3,"file":"DefaultErrorInfo.js","sourceRoot":"","sources":["../../src/defaults/DefaultErrorInfo.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAG/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA6B,CAAC,KAAK,EAAE,EAAE,CAAC,CACnE,oBAAC,aAAa,IAAC,IAAI,EAAC,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,oBAAC,eAAe,oBAAK,KAAK,EAAI,GAAI,CAC3F,CAAC;AACF,gBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC"}
@@ -8,7 +8,7 @@ const components_1 = require("../components");
8
8
  * Leverage the default one by registration of respective extensions using
9
9
  * the "error" name.
10
10
  */
11
- const DefaultErrorInfo = (props) => (React.createElement(components_1.ExtensionSlot, { name: "error", params: props, empty: () => React.createElement(components_1.SwitchErrorInfo, Object.assign({ key: "default_error" }, props)) }));
11
+ const DefaultErrorInfo = (props) => (React.createElement(components_1.ExtensionSlot, { name: "error", params: props, empty: () => React.createElement(components_1.SwitchErrorInfo, Object.assign({}, props)) }));
12
12
  exports.DefaultErrorInfo = DefaultErrorInfo;
13
13
  exports.DefaultErrorInfo.displayName = 'DefaultErrorInfo';
14
14
  //# sourceMappingURL=DefaultErrorInfo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DefaultErrorInfo.js","sourceRoot":"","sources":["../../src/defaults/DefaultErrorInfo.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,8CAA+D;AAG/D;;;;GAIG;AACI,MAAM,gBAAgB,GAA6B,CAAC,KAAK,EAAE,EAAE,CAAC,CACnE,oBAAC,0BAAa,IAAC,IAAI,EAAC,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,oBAAC,4BAAe,kBAAC,GAAG,EAAC,eAAe,IAAK,KAAK,EAAI,GAAI,CAC/G,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AACF,wBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC"}
1
+ {"version":3,"file":"DefaultErrorInfo.js","sourceRoot":"","sources":["../../src/defaults/DefaultErrorInfo.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,8CAA+D;AAG/D;;;;GAIG;AACI,MAAM,gBAAgB,GAA6B,CAAC,KAAK,EAAE,EAAE,CAAC,CACnE,oBAAC,0BAAa,IAAC,IAAI,EAAC,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,oBAAC,4BAAe,oBAAK,KAAK,EAAI,GAAI,CAC3F,CAAC;AAFW,QAAA,gBAAgB,oBAE3B;AACF,wBAAgB,CAAC,WAAW,GAAG,kBAAkB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "0.15.0-alpha.4345",
3
+ "version": "0.15.0-alpha.4399",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -71,8 +71,8 @@
71
71
  "test": "echo \"Error: run tests from root\" && exit 1"
72
72
  },
73
73
  "dependencies": {
74
- "piral-base": "0.15.0-alpha.4345",
75
- "piral-debug-utils": "0.15.0-alpha.4345",
74
+ "piral-base": "0.15.0-alpha.4399",
75
+ "piral-debug-utils": "0.15.0-alpha.4399",
76
76
  "zustand": "^3.0.0"
77
77
  },
78
78
  "peerDependencies": {
@@ -100,5 +100,5 @@
100
100
  "history",
101
101
  "tslib"
102
102
  ],
103
- "gitHead": "56ecd6ad080b3d275752b19afcf8435e4bd09140"
103
+ "gitHead": "34be0cac6948a92981ab4994b01b34e44462e7a0"
104
104
  }
@@ -1,30 +1,19 @@
1
1
  import * as React from 'react';
2
- import { act } from 'react-dom/test-utils';
3
- import { mount, ReactWrapper } from 'enzyme';
2
+ import { render, act } from '@testing-library/react';
4
3
  import { Piral } from './Piral';
5
- import { RegisteredRouter } from './components';
6
4
  import { createInstance } from './createInstance';
7
5
 
8
- function resolveAfter(time = 5) {
9
- return new Promise<void>((resolve) => setTimeout(resolve, time));
10
- }
11
-
12
- async function waitForComponentToPaint<P = {}>(wrapper: ReactWrapper<P>, amount = 5) {
13
- await act(resolveAfter);
14
- wrapper.update();
15
- }
16
-
17
6
  describe('Piral Component', () => {
18
7
  it('renders the Piral instance with default settings', async () => {
19
- const node = mount(<Piral />);
20
- await waitForComponentToPaint(node);
21
- expect(node.find(RegisteredRouter).length).toBe(1);
8
+ const node = render(<Piral />);
9
+ await act(() => Promise.resolve());
10
+ expect(node.container.childNodes.length).toBe(1);
22
11
  });
23
12
 
24
13
  it('renders the Piral instance with custom settings', async () => {
25
14
  const instance = createInstance();
26
- const node = mount(<Piral instance={instance} />);
27
- await waitForComponentToPaint(node);
28
- expect(node.find(RegisteredRouter).length).toBe(1);
15
+ const node = render(<Piral instance={instance} />);
16
+ await act(() => Promise.resolve());
17
+ expect(node.container.childNodes.length).toBe(1);
29
18
  });
30
19
  });
@@ -1,6 +1,5 @@
1
1
  import * as React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { act } from 'react-dom/test-utils';
2
+ import { render, act } from '@testing-library/react';
4
3
  import { RootListener } from './RootListener';
5
4
 
6
5
  jest.mock('./hooks/globalState', () => ({
@@ -10,7 +9,7 @@ jest.mock('./hooks/globalState', () => ({
10
9
  }));
11
10
 
12
11
  function resolveAfter(time = 5) {
13
- return new Promise<void>(resolve => setTimeout(resolve, time));
12
+ return new Promise<void>((resolve) => setTimeout(resolve, time));
14
13
  }
15
14
 
16
15
  describe('RootListener Component', () => {
@@ -18,9 +17,7 @@ describe('RootListener Component', () => {
18
17
  const element = document.createElement('div');
19
18
  const removed = jest.fn();
20
19
  document.body.appendChild(element);
21
- const container = document.body.appendChild(document.createElement('div'));
22
- const root = createRoot(container);
23
- root.render(<RootListener />);
20
+ render(<RootListener />);
24
21
  document.body.removeEventListener = removed;
25
22
  await act(() => {
26
23
  const event = new CustomEvent('render-html', {
@@ -38,13 +35,11 @@ describe('RootListener Component', () => {
38
35
  });
39
36
 
40
37
  it('removes the RootListener successfully', async () => {
41
- const container = document.body.appendChild(document.createElement('div'));
42
38
  const removed = jest.fn();
43
- const root = createRoot(container);
44
- root.render(<RootListener />);
39
+ const container = render(<RootListener />);
45
40
  document.body.removeEventListener = removed;
46
41
  await act(resolveAfter);
47
- root.unmount();
42
+ container.unmount();
48
43
  await act(resolveAfter);
49
44
  expect(removed).toHaveBeenCalled();
50
45
  });
@@ -1,5 +1,5 @@
1
1
  import create from 'zustand';
2
- import { mount } from 'enzyme';
2
+ import { render } from '@testing-library/react';
3
3
  import { createElement } from 'react';
4
4
  import { createListener, Pilet } from 'piral-base';
5
5
  import {
@@ -104,9 +104,9 @@ describe('App Actions Module', () => {
104
104
  const NewProvider = state.getState().provider;
105
105
  expect(NewProvider).not.toBeUndefined();
106
106
 
107
- const node = mount(createElement(NewProvider, undefined, 'Some text'));
108
- expect(node.find('div').length).toBe(1);
109
- expect(node.text()).toBe('Some text');
107
+ const node = render(createElement(NewProvider, undefined, 'Some text'));
108
+ expect(node.container.querySelectorAll('div').length).toBe(1);
109
+ expect(node.container.textContent).toBe('Some text');
110
110
  });
111
111
 
112
112
  it('allows using includeProvider twice', () => {
@@ -122,10 +122,10 @@ describe('App Actions Module', () => {
122
122
  const NewProvider = state.getState().provider;
123
123
  expect(NewProvider).not.toBeUndefined();
124
124
 
125
- const node = mount(createElement(NewProvider, undefined, 'Some text'));
126
- expect(node.find('b').length).toBe(1);
127
- expect(node.find('i').length).toBe(1);
128
- expect(node.text()).toBe('Some text');
125
+ const node = render(createElement(NewProvider, undefined, 'Some text'));
126
+ expect(node.container.querySelectorAll('b').length).toBe(1);
127
+ expect(node.container.querySelectorAll('i').length).toBe(1);
128
+ expect(node.container.textContent).toBe('Some text');
129
129
  });
130
130
 
131
131
  it('allows using includeProvider with props', () => {
@@ -139,10 +139,10 @@ describe('App Actions Module', () => {
139
139
  const NewProvider = state.getState().provider;
140
140
  expect(NewProvider).not.toBeUndefined();
141
141
 
142
- const node = mount(createElement(NewProvider, undefined, 'Some text'));
143
- expect(node.find('b').length).toBe(0);
144
- expect(node.find('i').length).toBe(1);
145
- expect(node.text()).toBe('IcecreamSome text');
142
+ const node = render(createElement(NewProvider, undefined, 'Some text'));
143
+ expect(node.container.querySelectorAll('b').length).toBe(0);
144
+ expect(node.container.querySelectorAll('i').length).toBe(1);
145
+ expect(node.container.textContent).toBe('IcecreamSome text');
146
146
  });
147
147
 
148
148
  it('allows multiple includeProvider with props', () => {
@@ -158,9 +158,9 @@ describe('App Actions Module', () => {
158
158
  const NewProvider = state.getState().provider;
159
159
  expect(NewProvider).not.toBeUndefined();
160
160
 
161
- const node = mount(createElement(NewProvider, undefined, 'Some text'));
162
- expect(node.find('b').length).toBe(1);
163
- expect(node.find('i').length).toBe(1);
164
- expect(node.text()).toBe('IcecreamChocolateSome text');
161
+ const node = render(createElement(NewProvider, undefined, 'Some text'));
162
+ expect(node.container.querySelectorAll('b').length).toBe(1);
163
+ expect(node.container.querySelectorAll('i').length).toBe(1);
164
+ expect(node.container.textContent).toBe('IcecreamChocolateSome text');
165
165
  });
166
166
  });
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { mount } from 'enzyme';
2
+ import { render } from '@testing-library/react';
3
3
  import { ExtensionSlot } from './ExtensionSlot';
4
4
 
5
5
  jest.mock('../hooks/globalState', () => ({
@@ -15,18 +15,19 @@ jest.mock('../hooks/globalState', () => ({
15
15
  },
16
16
  },
17
17
  },
18
+ destroyPortal: jest.fn(),
18
19
  }),
19
20
  }));
20
21
 
21
22
  (React as any).useMemo = (cb) => cb();
22
23
 
23
- const StubComponent1: React.FC = (props) => <div children={props.children} />;
24
+ const StubComponent1: React.FC<any> = (props) => <div role="stub1" children={props.children} />;
24
25
  StubComponent1.displayName = 'StubComponent1';
25
26
 
26
- const StubComponent2: React.FC = (props) => <div children={props.children} />;
27
+ const StubComponent2: React.FC<any> = (props) => <div role="stub2" children={props.children} />;
27
28
  StubComponent2.displayName = 'StubComponent2';
28
29
 
29
- const StubComponent3: React.FC = (props) => <div children={props.children} />;
30
+ const StubComponent3: React.FC<any> = (props) => <div role="stub3" children={props.children} />;
30
31
 
31
32
  const state = {
32
33
  portals: {},
@@ -60,10 +61,9 @@ const state = {
60
61
 
61
62
  describe('Extension Module', () => {
62
63
  it('is able to default render not available extension with no name', () => {
63
- const node = mount(<ExtensionSlot />);
64
- expect(node.at(0).exists()).toBe(true);
65
- expect(node.find(StubComponent1).length).toBe(0);
66
- expect(node.find('div').length).toBe(0);
64
+ const node = render(<ExtensionSlot />);
65
+ expect(node.queryAllByRole("stub1").length).toBe(0);
66
+ expect(node.container.querySelectorAll('div').length).toBe(0);
67
67
  });
68
68
 
69
69
  it('is able to default render given component with no name', () => {
@@ -71,81 +71,78 @@ describe('Extension Module', () => {
71
71
  type: 'html',
72
72
  component: {
73
73
  mount(element) {
74
- const container = document.createElement('div');
74
+ const container = document.createElement('strong');
75
75
  container.textContent = 'Hello!';
76
76
  element.appendChild(container);
77
77
  },
78
78
  },
79
79
  };
80
- const node = mount(<ExtensionSlot params={{ component }} />);
81
- expect(node.at(0).exists()).toBe(true);
82
- expect(node.find(StubComponent1).length).toBe(0);
83
- expect(node.find('div').length).toBe(1);
84
- expect(node.text()).toContain('Hello!');
80
+ const node = render(<ExtensionSlot params={{ component }} />);
81
+ expect(node.queryAllByRole("stub1").length).toBe(0);
82
+ expect(node.container.querySelectorAll('strong').length).toBe(1);
83
+ expect(node.container.textContent).toContain('Hello!');
85
84
  });
86
85
 
87
86
  it('is able to default render not available extension', () => {
88
- const node = mount(<ExtensionSlot name="qxz" />);
89
- expect(node.at(0).exists()).toBe(true);
90
- expect(node.find(StubComponent1).length).toBe(0);
87
+ const node = render(<ExtensionSlot name="qxz" />);
88
+ expect(node.queryAllByRole("stub1").length).toBe(0);
91
89
  });
92
90
 
93
91
  it('is able to (default) render empty extension', () => {
94
- const node = mount(<ExtensionSlot name="foo" />);
95
- expect(node.at(0).exists()).toBe(true);
96
- expect(node.find(StubComponent1).length).toBe(0);
92
+ const node = render(<ExtensionSlot name="foo" />);
93
+ expect(node.queryAllByRole("stub1").length).toBe(0);
97
94
  });
98
95
 
99
96
  it('is able to custom render not available extension', () => {
100
- const node = mount(<ExtensionSlot name="qxz" render={() => <StubComponent1 />} />);
101
- expect(node.find(StubComponent1).length).toBe(1);
97
+ const node = render(<ExtensionSlot name="qxz" render={() => <StubComponent1 />} />);
98
+ expect(node.queryAllByRole("stub1").length).toBe(1);
102
99
  });
103
100
 
104
101
  it('is able to (custom) render empty extension', () => {
105
- const node = mount(<ExtensionSlot name="foo" render={() => <StubComponent1 />} />);
106
- expect(node.find(StubComponent1).length).toBe(1);
102
+ const node = render(<ExtensionSlot name="foo" render={() => <StubComponent1 />} />);
103
+ expect(node.queryAllByRole("stub1").length).toBe(1);
107
104
  });
108
105
 
109
106
  it('is able to render extension with multiple entries', () => {
110
- const node = mount(<ExtensionSlot name="bar" />);
111
- expect(node.find(StubComponent1).length).toBe(2);
112
- expect(node.find(StubComponent2).length).toBe(1);
113
- expect(node.find(StubComponent3).length).toBe(0);
107
+ const node = render(<ExtensionSlot name="bar" />);
108
+ expect(node.queryAllByRole("stub1").length).toBe(2);
109
+ expect(node.queryAllByRole("stub2").length).toBe(1);
110
+ expect(node.queryAllByRole("stub3").length).toBe(0);
114
111
  });
115
112
 
116
113
  it('is able to render extension without displayName', () => {
117
- const node = mount(<ExtensionSlot name="bla" />);
118
- expect(node.find(StubComponent1).length).toBe(0);
119
- expect(node.find(StubComponent2).length).toBe(0);
120
- expect(node.find(StubComponent3).length).toBe(1);
114
+ const node = render(<ExtensionSlot name="bla" />);
115
+ expect(node.queryAllByRole("stub1").length).toBe(0);
116
+ expect(node.queryAllByRole("stub2").length).toBe(0);
117
+ expect(node.queryAllByRole("stub3").length).toBe(1);
121
118
  });
122
119
 
123
120
  it('overrides the empty renderer on not available extension', () => {
124
- const node = mount(<ExtensionSlot name="qxz" empty={() => <StubComponent1 key="empty" />} />);
125
- expect(node.find(StubComponent1).length).toBe(1);
126
- expect(node.find(StubComponent2).length).toBe(0);
121
+ const node = render(<ExtensionSlot name="qxz" empty={() => <StubComponent1 key="empty" />} />);
122
+ expect(node.queryAllByRole("stub1").length).toBe(1);
123
+ expect(node.queryAllByRole("stub2").length).toBe(0);
127
124
  });
128
125
 
129
126
  it('overrides the empty renderer on an available extension', () => {
130
- const node = mount(<ExtensionSlot name="foo" empty={() => <StubComponent2 key="empty" />} />);
131
- expect(node.find(StubComponent1).length).toBe(0);
132
- expect(node.find(StubComponent2).length).toBe(1);
127
+ const node = render(<ExtensionSlot name="foo" empty={() => <StubComponent2 key="empty" />} />);
128
+ expect(node.queryAllByRole("stub1").length).toBe(0);
129
+ expect(node.queryAllByRole("stub2").length).toBe(1);
133
130
  });
134
131
 
135
132
  it('overrides the empty and default renderer on an available extension', () => {
136
- const node = mount(
133
+ const node = render(
137
134
  <ExtensionSlot
138
135
  name="foo"
139
136
  empty={() => <StubComponent2 key="empty" />}
140
137
  render={(nodes) => <StubComponent1 children={nodes} />}
141
138
  />,
142
139
  );
143
- expect(node.find(StubComponent1).length).toBe(1);
144
- expect(node.find(StubComponent2).length).toBe(1);
140
+ expect(node.queryAllByRole("stub1").length).toBe(1);
141
+ expect(node.queryAllByRole("stub2").length).toBe(1);
145
142
  });
146
143
 
147
144
  it('does not use the render function with empty when emptySkipsRender is set', () => {
148
- const node = mount(
145
+ const node = render(
149
146
  <ExtensionSlot
150
147
  name="foo"
151
148
  emptySkipsRender
@@ -153,12 +150,12 @@ describe('Extension Module', () => {
153
150
  render={(nodes) => <StubComponent1 children={nodes} />}
154
151
  />,
155
152
  );
156
- expect(node.find(StubComponent1).length).toBe(0);
157
- expect(node.find(StubComponent2).length).toBe(1);
153
+ expect(node.queryAllByRole("stub1").length).toBe(0);
154
+ expect(node.queryAllByRole("stub2").length).toBe(1);
158
155
  });
159
156
 
160
157
  it('does use the render function without empty independent if emptySkipsRender is set', () => {
161
- const node = mount(
158
+ const node = render(
162
159
  <ExtensionSlot
163
160
  name="lol"
164
161
  emptySkipsRender
@@ -166,7 +163,7 @@ describe('Extension Module', () => {
166
163
  render={(nodes) => <StubComponent1 children={nodes} />}
167
164
  />,
168
165
  );
169
- expect(node.find(StubComponent1).length).toBe(2);
170
- expect(node.find(StubComponent2).length).toBe(0);
166
+ expect(node.queryAllByRole("stub1").length).toBe(2);
167
+ expect(node.queryAllByRole("stub2").length).toBe(0);
171
168
  });
172
169
  });
@@ -1,65 +1,53 @@
1
1
  import * as React from 'react';
2
- import { createRoot } from 'react-dom/client';
3
- import { act } from 'react-dom/test-utils';
2
+ import { render, act } from '@testing-library/react';
4
3
  import { ForeignComponentContainer } from './ForeignComponentContainer';
5
4
 
6
5
  function resolveAfter(time = 5) {
7
- return new Promise<void>(resolve => setTimeout(resolve, time));
8
- }
9
-
10
- async function render(element: any, container: Element) {
11
- const root = createRoot(container);
12
- root.render(element);
13
- await act(resolveAfter);
14
- return root;
6
+ return new Promise<void>((resolve) => setTimeout(resolve, time));
15
7
  }
16
8
 
17
9
  describe('ForeignComponentContainer component', () => {
18
10
  it('mounts an HTML component', async () => {
19
- const container = document.body.appendChild(document.createElement('div'));
20
11
  const mount = jest.fn();
21
12
  const component = { mount };
22
- await render(
13
+ const container = render(
23
14
  <ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
24
- container,
25
15
  );
16
+ await act(resolveAfter);
26
17
  expect(mount).toHaveBeenCalled();
27
- container.remove();
18
+ container.unmount();
28
19
  });
29
20
 
30
21
  it('unmounts an HTML component', async () => {
31
- const container = document.body.appendChild(document.createElement('div'));
32
22
  const mount = jest.fn();
33
23
  const unmount = jest.fn();
34
24
  const component = { mount, unmount };
35
- const root = await render(
25
+ const container = render(
36
26
  <ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={{}} />,
37
- container,
38
27
  );
28
+ await act(resolveAfter);
39
29
  expect(mount).toHaveBeenCalled();
40
30
  expect(unmount).not.toHaveBeenCalled();
41
- root.unmount();
31
+ container.unmount();
42
32
  expect(unmount).toHaveBeenCalled();
43
- container.remove();
44
33
  });
45
34
 
46
35
  it('updates an HTML component', async () => {
47
- const container = document.body.appendChild(document.createElement('div'));
48
36
  const mount = jest.fn();
49
37
  const update = jest.fn();
50
38
  const component = { mount, update };
51
- const root = await render(
39
+ const container = render(
52
40
  <ForeignComponentContainer
53
41
  $component={component}
54
42
  $context={undefined}
55
43
  $portalId="foo"
56
44
  innerProps={{ a: 'bar' }}
57
45
  />,
58
- container,
59
46
  );
47
+ await act(resolveAfter);
60
48
  expect(mount).toHaveBeenCalled();
61
49
  expect(update).not.toHaveBeenCalled();
62
- root.render(
50
+ container.rerender(
63
51
  <ForeignComponentContainer
64
52
  $component={component}
65
53
  $context={undefined}
@@ -69,35 +57,34 @@ describe('ForeignComponentContainer component', () => {
69
57
  );
70
58
  await act(resolveAfter);
71
59
  expect(update).toHaveBeenCalled();
72
- container.remove();
60
+ container.unmount();
73
61
  });
74
62
 
75
63
  it('forces re-rendering of an HTML component', async () => {
76
- const container = document.body.appendChild(document.createElement('div'));
77
64
  const componentDidMount = ForeignComponentContainer.prototype.componentDidMount;
78
65
  ForeignComponentContainer.prototype.componentDidMount = function () {
79
66
  componentDidMount.call(this);
80
67
  this.previous = {
81
- removeEventListener() { },
68
+ removeEventListener() {},
82
69
  };
83
70
  };
84
71
  const mount = jest.fn();
85
72
  const update = jest.fn();
86
73
  const unmount = jest.fn();
87
74
  const component = { mount, update, unmount };
88
- const root = await render(
75
+ const container = render(
89
76
  <ForeignComponentContainer
90
77
  $component={component}
91
78
  $context={undefined}
92
79
  $portalId="foo"
93
80
  innerProps={{ a: 'bar' }}
94
81
  />,
95
- container,
96
82
  );
83
+ await act(resolveAfter);
97
84
  expect(mount).toHaveBeenCalled();
98
85
  expect(unmount).not.toHaveBeenCalled();
99
86
  expect(update).not.toHaveBeenCalled();
100
- root.render(
87
+ container.rerender(
101
88
  <ForeignComponentContainer
102
89
  $component={component}
103
90
  $context={undefined}
@@ -108,25 +95,24 @@ describe('ForeignComponentContainer component', () => {
108
95
  await act(resolveAfter);
109
96
  expect(update).not.toHaveBeenCalled();
110
97
  expect(unmount).toHaveBeenCalled();
111
- container.remove();
98
+ container.unmount();
112
99
  });
113
100
 
114
101
  it('listens to render-html', async () => {
115
- const container = document.body.appendChild(document.createElement('div'));
116
102
  const mount = jest.fn();
117
103
  const renderHtmlExtension = jest.fn();
118
104
  const component = { mount };
119
105
  const props = { piral: { renderHtmlExtension }, meta: {} };
120
- await render(
106
+ const container = render(
121
107
  <ForeignComponentContainer $component={component} $context={undefined} $portalId="foo" innerProps={props} />,
122
- container,
123
108
  );
109
+ await act(resolveAfter);
124
110
  expect(mount).toHaveBeenCalled();
125
111
  const node = document.querySelector('[data-portal-id=foo]');
126
112
  expect(renderHtmlExtension).not.toHaveBeenCalled();
127
- node.dispatchEvent(new CustomEvent('render-html', { detail: {} }));
113
+ node?.dispatchEvent(new CustomEvent('render-html', { detail: {} }));
128
114
  await act(resolveAfter);
129
115
  expect(renderHtmlExtension).toHaveBeenCalled();
130
- container.remove();
116
+ container.unmount();
131
117
  });
132
118
  });
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import create from 'zustand';
3
+ import { render } from '@testing-library/react';
3
4
  import { Mediator } from './Mediator';
4
- import { mount } from 'enzyme';
5
5
  import { StateContext } from '../state';
6
6
  import { PiletMetadata } from '../types';
7
7
 
@@ -50,7 +50,7 @@ describe('Component Mediator', () => {
50
50
  },
51
51
  };
52
52
  const { context } = createMockContainer();
53
- const node = mount(
53
+ render(
54
54
  <StateContext.Provider value={context}>
55
55
  <Mediator options={options} />
56
56
  </StateContext.Provider>,