jest-next-dynamic
Advanced tools
Comparing version 0.2.0 to 0.3.0
37
index.js
@@ -5,8 +5,10 @@ const mockInitializers = []; | ||
if (mockInitializers.length) { | ||
const promises = mockInitializers.map(preload => preload()); | ||
// Copy and empty out `mockInitializers` right away so that any newly | ||
// enqueued components are found in the next pass. | ||
const initializers = mockInitializers.slice(); | ||
mockInitializers.length = 0; | ||
// While loading the components in this round of initializers, more | ||
// components may have been dynamically loaded, adding more promises we | ||
// should wait for. | ||
return Promise.all(promises).then(preloadAll); | ||
// components may have been dynamically imported, adding more initializers | ||
// we should run and await. | ||
return Promise.all(initializers.map(preload => preload())).then(preloadAll); | ||
} else { | ||
@@ -17,12 +19,21 @@ return Promise.resolve(); | ||
jest.doMock("next/dynamic", () => { | ||
const { default: dynamic } = jest.requireActual("next/dynamic"); | ||
jest.doMock( | ||
"next/dynamic", | ||
() => { | ||
const { default: dynamic } = jest.requireActual("next/dynamic"); | ||
const mockDynamic = (...args) => { | ||
const LoadableComponent = dynamic(...args); | ||
mockInitializers.push(() => LoadableComponent.preload()); | ||
return LoadableComponent; | ||
}; | ||
const mockDynamic = (...args) => { | ||
const LoadableComponent = dynamic(...args); | ||
mockInitializers.push(() => LoadableComponent.preload()); | ||
return LoadableComponent; | ||
}; | ||
return mockDynamic; | ||
}); | ||
return mockDynamic; | ||
}, | ||
// In order to more easily include this feature in shared Jest setups (like | ||
// presets), use `virtual: true` to avoid throwing an error when `next` isn't | ||
// actually installed. | ||
{ | ||
virtual: true | ||
} | ||
); |
{ | ||
"name": "jest-next-dynamic", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3400
33