Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it(`is never bootstrapped`, () => {
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.isBootstrapped()).toEqual(false);
expect(singleSpa.getMountedApps()).toEqual([]);
expect(singleSpa.getAppStatus('./invalid-no-mount.app.js')).toEqual('SKIP_BECAUSE_BROKEN');
})
});
it(`goes through the whole lifecycle successfully`, () => {
expect(myApp.isMounted()).toEqual(false);
expect(singleSpa.getMountedApps()).toEqual([]);
location.hash = 'happy-basic';
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.wasBootstrapped()).toEqual(true);
expect(myApp.isMounted()).toEqual(true);
expect(singleSpa.getMountedApps()).toEqual(['./happy-basic.app.js']);
location.hash = '#not-happy-basic';
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.wasBootstrapped()).toEqual(true);
expect(myApp.isMounted()).toEqual(false);
expect(singleSpa.getMountedApps()).toEqual([]);
})
})
it(`is bootstrapped and mounted, but then put in a broken state`, () => {
location.hash = activeHash;
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.wasBootstrapped()).toEqual(true);
expect(myApp.wasMounted()).toEqual(true);
expect(singleSpa.getMountedApps()).toEqual([]);
expect(singleSpa.getAppStatus('./invalid-mount.app.js')).toEqual('SKIP_BECAUSE_BROKEN');
location.hash = 'not-invalid-mount';
return singleSpa
.triggerAppChange()
.then(() => {
expect(singleSpa.getMountedApps()).toEqual([]);
expect(singleSpa.getAppStatus('./invalid-mount.app.js')).toEqual('SKIP_BECAUSE_BROKEN');
})
})
it(`goes through the whole lifecycle successfully`, () => {
expect(myApp.wasMounted()).toEqual(false);
expect(singleSpa.getMountedApps()).toEqual([]);
location.hash = '#returns-non-native-promise';
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.wasBootstrapped()).toEqual(true);
expect(myApp.wasMounted()).toEqual(true);
expect(singleSpa.getMountedApps()).toEqual(['./returns-non-native-promise.app.js']);
location.hash = '#something-else';
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.wasBootstrapped()).toEqual(true);
expect(myApp.wasUnmounted()).toEqual(true);
expect(singleSpa.getMountedApps()).toEqual([]);
})
})
it(`should throw an error when mounting fails`, () => {
const app = createApp();
let shouldAppBeMounted = true;
singleSpa.registerApplication('parcel-bootstrap-errors', app, () => shouldAppBeMounted);
return singleSpa.triggerAppChange().then(() => {
expect(app.mountCalls).toBe(1)
const parcelConfig1 = createParcelConfig('bootstrap')
parcelConfig1.name = 'bootstrap-error'
const parcel1 = app.mountProps.mountParcel(parcelConfig1, {domElement: document.createElement('div')})
return parcel1.bootstrapPromise.catch(err => {
expect(err.name).toBe('bootstrap-error');
expect(err.message.indexOf(`SKIP_BECAUSE_BROKEN`)).toBeGreaterThan(-1);
expect(err.message.indexOf(`bootstrap-error`)).toBeGreaterThan(-1);
}).then(() => {
expect(parcel1.getStatus()).toBe('SKIP_BECAUSE_BROKEN')
})
})
})
it(`bootstraps and mounts, but then is put into SKIP_BECAUSE_BROKEN once it unmounts`, () => {
location.hash = activeHash;
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.numBootstraps()).toEqual(1);
expect(myApp.numMounts()).toEqual(1);
expect(myApp.numUnmounts()).toEqual(0);
expect(singleSpa.getMountedApps()).toEqual(['./unmount-rejects.app.js']);
expect(singleSpa.getAppStatus('./unmount-rejects.app.js')).toEqual('MOUNTED');
location.hash = '#not-unmount-rejects';
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.numUnmounts()).toEqual(1);
expect(singleSpa.getMountedApps()).toEqual([]);
expect(singleSpa.getAppStatus('./unmount-rejects.app.js')).toEqual('SKIP_BECAUSE_BROKEN');
it(`unloads an app that is mounted, and then remounts it`, () => {
location.hash = activeHash;
return singleSpa
.triggerAppChange()
.then(() => {
expect(singleSpa.getAppStatus('./happy-unload.app.js')).toEqual('MOUNTED');
expect(myApp.getNumBootstrapCalls()).toBe(1);
expect(myApp.getNumMountCalls()).toBe(1);
expect(myApp.getNumUnmountCalls()).toBe(0);
expect(myApp.getNumUnloadCalls()).toBe(0);
location.hash = '#';
return singleSpa.unloadApplication('./happy-unload.app.js');
})
.then(() => {
expect(singleSpa.getAppStatus('./happy-unload.app.js')).toEqual('NOT_LOADED');
expect(myApp.getNumBootstrapCalls()).toBe(1);
expect(myApp.getNumMountCalls()).toBe(1);
expect(myApp.getNumUnmountCalls()).toBe(1);
expect(myApp.getNumUnloadCalls()).toBe(1);
it(`is just waited for if dieOnTimeout is false`, () => {
location.hash = '#bootstrap-times-out';
return singleSpa
.triggerAppChange()
.then(() => {
expect(myApp.wasBootstrapped()).toEqual(true);
expect(myApp.wasMounted()).toEqual(true);
expect(singleSpa.getMountedApps()).toEqual(['./bootstrap-times-out.app.js']);
expect(singleSpa.getAppStatus('./bootstrap-times-out.app.js')).toEqual(singleSpa.MOUNTED);
expect(errs.length).toBe(0);
})
});
});
parcelConfig = createParcelConfig();
shouldAppBeMounted = true;
expect(app.bootstrapCalls).toBe(0);
expect(app.mountCalls).toBe(0);
expect(app.unmountCalls).toBe(0);
expect(parcelConfig.bootstrapCalls).toBe(0);
expect(parcelConfig.mountCalls).toBe(0);
expect(parcelConfig.unmountCalls).toBe(0);
let parcel, unmountPromiseHasResolved = false;
return singleSpa
.triggerAppChange()
.then(() => {
expect(app.bootstrapCalls).toBe(1);
expect(app.mountCalls).toBe(1);
expect(app.unmountCalls).toBe(0);
parcel = app.mountProps.mountParcel(parcelConfig, {domElement: document.createElement('div')});
parcel.unmountPromise
.then(() => unmountPromiseHasResolved = true)
expect(parcel.getStatus()).toBe(singleSpa.NOT_BOOTSTRAPPED);
expect(unmountPromiseHasResolved).toBe(false);
return parcel
.bootstrapPromise
.then(() => {
expect(bootstrapped).toEqual(true);
expect(mounted).toEqual(true);
expect(singleSpa.getMountedApps()).toEqual(['register-with-object']);
location.hash = '#not-register-with-object';
return singleSpa
.triggerAppChange()
.then(() => {
expect(bootstrapped).toEqual(true);
expect(mounted).toEqual(false);
expect(singleSpa.getMountedApps()).toEqual([]);
})
})
});