Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(`does not allow you to call update on a parcel that does not implement the update lifecycle`, () => {
const parcelConfig = createParcelConfig();
const parcel = singleSpa.mountRootParcel(parcelConfig, {domElement: document.createElement('div')});
return parcel
.mountPromise
.then(() => expect(parcel.update).toBeUndefined())
})
});
it(`should throw an error if you call update on a parcel does not implement the 'update' lifecycle`, () => {
const parcelConfig = createParcelConfig()
const parcel = singleSpa.mountRootParcel(parcelConfig, {domElement: document.createElement('div')})
return parcel
.mountPromise
.then(() => {
expect(() => parcel.update({})).toThrow()
})
})
})
it(`allows you to update a parcel that has implemented the update lifecycle`, () => {
const parcelConfig = createParcelConfig({withUpdate: true});
const parcel = singleSpa.mountRootParcel(parcelConfig, {domElement: document.createElement('div')});
return parcel
.mountPromise
.then(() => expect(typeof parcel.update).toBe('function'))
.then(() => expect(parcelConfig.updateCalls).toBe(0))
.then(() => parcel.update({}))
.then(resolvedVal => expect(resolvedVal).toBe(null))
.then(() => expect(parcelConfig.updateCalls).toBe(1))
})
it(`rejects the load promise if the config doesn't have a valid bootstrap function`, () => {
const parcel = singleSpa.mountRootParcel({mount() {}, unmount() {}}, {domElement: document.createElement('div')})
return parcel.loadPromise.then(
() => {
throw new Error('load promise should not have succeeded')
},
err => {
expect(err.message.indexOf('must have a valid bootstrap function')).toBeGreaterThan(-1)
}
)
})
it(`can mount and unmount root parcels`, () => {
const parcelConfig = createParcelConfig();
const parcel = singleSpa.mountRootParcel(parcelConfig, {domElement: document.createElement('div')});
expect(parcel.getStatus()).toBe(singleSpa.NOT_BOOTSTRAPPED);
return parcel
.mountPromise
.then(() => {
expect(parcel.getStatus()).toBe(singleSpa.MOUNTED);
})
.then(() => new Promise((resolve, reject) => {
setTimeout(resolve, 20);
}))
.then(parcel.unmount)
.then(() => {
expect(parcel.getStatus()).toBe(singleSpa.NOT_MOUNTED);
})
});
it(`lets you call mountParcel with a config loading function instead of an actual parcel config`, () => {
const parcelConfig = createParcelConfig();
let resolveConfigLoading
const configLoadingFunction = () => new Promise(resolve => {
resolveConfigLoading = () => resolve(parcelConfig)
})
const parcel = singleSpa.mountRootParcel(configLoadingFunction, {domElement: document.createElement('div')});
expect(parcel.getStatus()).toBe(singleSpa.LOADING_SOURCE_CODE);
return Promise
.resolve()
.then(() => expect(parcel.getStatus()).toBe(singleSpa.LOADING_SOURCE_CODE))
.then(() => resolveConfigLoading())
.then(() => parcel.loadPromise)
.then(() => expect(parcel.getStatus()).not.toBe(singleSpa.LOADING_SOURCE_CODE))
.then(() => parcel.mountPromise)
.then(() => expect(parcel.getStatus()).toBe(singleSpa.MOUNTED))
.then(() => parcel.unmount())
.then(() => expect(parcel.getStatus()).toBe(singleSpa.NOT_MOUNTED))
.then(() => parcel.unmountPromise)
})
it(`doesn't resolve bootstrapPromise, mountPromise, or unmountPromise with any values`, () => {
const parcelConfig = createParcelConfig();
const parcel = singleSpa.mountRootParcel(parcelConfig, {domElement: document.createElement('div')});
expect(parcel.getStatus()).toBe(singleSpa.NOT_BOOTSTRAPPED);
return parcel
.bootstrapPromise
.then(value => {
expect(value).toBe(null);
return parcel.mountPromise;
})
.then(value => {
expect(value).toBe(null);
return Promise.all([
parcel.unmountPromise,
parcel.unmount(),
]);
})
.then(values => {
async function controlledParcelActions(action, ...parcelArgs) {
const parcel = singleSpa.mountRootParcel(...generateParcel(...parcelArgs));
await flushPromises();
jest.advanceTimersByTime(2);
await flushPromises();
jest.advanceTimersByTime(1);
await flushPromises();
jest.advanceTimersByTime(2);
await flushPromises();
jest.advanceTimersByTime(7);
const actionPromise = action(parcel);
await flushPromises();
jest.advanceTimersByTime(3);
await flushPromises();
jest.advanceTimersByTime(7);
await actionPromise;
}
expect(() => {
singleSpa.mountRootParcel(null, {domElement: document.createElement('div')})
}).toThrow()
})