How to use the single-spa.mountRootParcel function in single-spa

To help you get started, we’ve selected a few single-spa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CanopyTax / single-spa / spec / parcels / mount-root-parcel.spec.js View on Github external
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())
  })
});
github CanopyTax / single-spa / spec / parcels / parcel-error-handlers.spec.js View on Github external
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()
          })
      })
    })
github CanopyTax / single-spa / spec / parcels / mount-root-parcel.spec.js View on Github external
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))
  })
github CanopyTax / single-spa / spec / parcels / parcel-error-handlers.spec.js View on Github external
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)
        }
      )
    })
github CanopyTax / single-spa / spec / parcels / mount-root-parcel.spec.js View on Github external
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);
      })
  });
github CanopyTax / single-spa / spec / parcels / mount-root-parcel.spec.js View on Github external
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)
  })
github CanopyTax / single-spa / spec / parcels / mount-root-parcel.spec.js View on Github external
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 => {
github CanopyTax / single-spa / spec / apis / timeout-apis.spec.js View on Github external
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;
}
github CanopyTax / single-spa / spec / parcels / parcel-error-handlers.spec.js View on Github external
expect(() => {
        singleSpa.mountRootParcel(null, {domElement: document.createElement('div')})
      }).toThrow()
    })