piral-lazy 0.15.0-alpha.3905 → 0.15.0-alpha.4005
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.
- package/package.json +3 -3
- package/src/create.test.ts +17 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-lazy",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.4005",
|
|
4
4
|
"description": "Plugin for lazy loading third-party framework components in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/react": "^17.0.0",
|
|
47
|
-
"piral-core": "0.15.0-alpha.
|
|
47
|
+
"piral-core": "0.15.0-alpha.4005",
|
|
48
48
|
"react": "^17.0.1"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"piral-core": "0.14.x",
|
|
52
52
|
"react": ">=16.8.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "612f2072dea6b5d02e3672be3972e850ae95d446"
|
|
55
55
|
}
|
package/src/create.test.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Atom, swap } from '@dbeining/react-atom';
|
|
2
|
+
import { render } from 'react-dom';
|
|
3
|
+
import { createElement, Suspense } from 'react';
|
|
2
4
|
import { createLazyApi } from './create';
|
|
5
|
+
import { act } from 'react-dom/test-utils';
|
|
3
6
|
|
|
4
7
|
function createMockContainer() {
|
|
5
8
|
const state = Atom.of({});
|
|
@@ -23,12 +26,20 @@ function createMockContainer() {
|
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
describe('Piral-Lazy create module', () => {
|
|
26
|
-
it('appends lazy loading for a DOM component', () => {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
+
it('appends lazy loading for a DOM component', async () => {
|
|
30
|
+
const mount = jest.fn();
|
|
31
|
+
const MyComponent = { component: { mount }, type: 'html' };
|
|
32
|
+
const load = async () => await Promise.resolve(MyComponent);
|
|
33
|
+
const { context, api } = createMockContainer();
|
|
29
34
|
const apiCreator: any = createLazyApi()(context);
|
|
30
|
-
const { fromLazy } = apiCreator();
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
const { fromLazy, defineDependency } = apiCreator(api);
|
|
36
|
+
defineDependency('testName', () => {});
|
|
37
|
+
const LazyComponent = fromLazy(load, ['testName']);
|
|
38
|
+
render(
|
|
39
|
+
createElement(Suspense, { fallback: 'anything' }, createElement(LazyComponent)),
|
|
40
|
+
document.body.appendChild(document.createElement('div')),
|
|
41
|
+
);
|
|
42
|
+
await act(() => Promise.resolve());
|
|
43
|
+
expect(LazyComponent).not.toBeUndefined();
|
|
33
44
|
});
|
|
34
45
|
});
|