Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('Dies if the load function returns a non-thenable object', () => {
function loadFunction() {
// return nothing
}
singleSpa.registerApplication('invalid-load-3', loadFunction, location => location.hash === "#invalid-load-function");
location.hash = "#invalid-load-function";
return singleSpa
.triggerAppChange()
.then(() => {
expect(errs.length).toBeGreaterThan(0);
expect(errs[0].appName).toBe('invalid-load-3');
expect(errs[0].message.indexOf('single-spa loading function did not return a promise. Check the second argument to registerApplication')).toBeGreaterThan(-1)
expect(singleSpa.getAppStatus('invalid-load-3')).toBe(singleSpa.SKIP_BECAUSE_BROKEN);
})
});
it('Dies if the load function returns nothing', () => {
function loadFunction() {
// return nothing
}
singleSpa.registerApplication('invalid-load-1', loadFunction, location => location.hash === "#invalid-load-function");
location.hash = "#invalid-load-function";
return singleSpa
.triggerAppChange()
.then(() => {
expect(errs.length).toBeGreaterThan(0);
expect(errs[0].appName).toBe('invalid-load-1');
expect(errs[0].message.indexOf('single-spa loading function did not return a promise. Check the second argument to registerApplication')).toBeGreaterThan(-1)
expect(singleSpa.getAppStatus('invalid-load-1')).toBe(singleSpa.SKIP_BECAUSE_BROKEN);
})
});
apiClient.init()
await telemetry.init()
const registry = new AppRegistry(options)
singleSpa.registerApplication(
'layout',
AppRegistry.newReactSpaApp(() => LayoutMain, 'root'),
() => {
return !routing.isSignInPage()
},
{ registry }
)
singleSpa.registerApplication(
'signin',
AppRegistry.newReactSpaApp(() => LayoutSignIn, 'root'),
() => {
return routing.isSignInPage()
},
{ registry }
)
registry
.register(AppDebugPlayground)
.register(AppDashboardSettings)
.register(AppUserProfile)
.register(AppOverview)
.register(AppKeyViz)
.register(AppStatement)
.register(AppClusterInfo)
it(`should remove the application so it can be re-registered`, () => {
singleSpa.registerApplication('about to unregister', app, () => false)
expect(singleSpa.getAppStatus('about to unregister')).toBeTruthy()
expect(() => {
singleSpa.registerApplication('about to unregister', app, () => false)
}).toThrow()
return window.__SINGLE_SPA_DEVTOOLS__.exposedMethods.unregisterApplication('about to unregister').then(() => {
expect(singleSpa.getAppStatus('about to unregister')).toBeFalsy()
})
})
})
it('can mount a parcel as a child of a parcel and unmount both together', () => {
const app = createApp();
let shouldAppBeMounted = true;
singleSpa.registerApplication('parcel-mounts-parcels', app, () => shouldAppBeMounted);
return singleSpa
.triggerAppChange()
.then(() => {
expect(app.mountCalls).toBe(1);
const parcelConfig1 = createParcelConfig();
const parcelConfig2 = createParcelConfig();
const parcel1 = app.mountProps.mountParcel(parcelConfig1, {domElement: document.createElement('div')})
return parcel1
.mountPromise
.then(() => {
expect(parcelConfig1.bootstrapCalls).toBe(1);
expect(parcelConfig1.mountCalls).toBe(1);
expect(parcelConfig1.unmountCalls).toBe(0);
it(`fires first-mount exactly once when the first app is mounted`, () => {
singleSpa.registerApplication('firstMount', dummyApp, () => {
return window.location.hash.indexOf('#/firstMount') === 0;
});
singleSpa.start();
let numFirstMounts = 0, numBeforeFirstMounts = 0;
window.addEventListener('single-spa:first-mount', () => {
numBeforeFirstMounts++;
});
window.addEventListener('single-spa:first-mount', () => {
numFirstMounts++;
});
window.location.hash = `#/firstMount`;
return singleSpa
beforeAll(() => {
singleSpa.registerApplication('./unmount-rejects.app.js', () => import('./unmount-rejects.app.js'), location => location.hash === activeHash);
singleSpa.start();
});
beforeAll(() => {
singleSpa.registerApplication('./invalid-unload.app.js', () => import('./invalid-unload.app.js'), location => location.hash === activeHash);
singleSpa.start();
});
beforeAll(() => {
singleSpa.registerApplication('./invalid-bootstrap.app.js', () => import('./invalid-bootstrap.app.js'), location => location.hash === activeHash);
singleSpa.start();
});
beforeAll(() => {
singleSpa.registerApplication('./mount-rejects.app.js', () => import('./mount-rejects.app.js'), location => location.hash === activeHash);
singleSpa.start();
});