rancher / dashboard

The Rancher UI
https://rancher.com
Apache License 2.0
450 stars 256 forks source link

Configure Jest to use async hook from Nuxt residual logic (e.g. fetch()) #9322

Open cnotv opened 1 year ago

cnotv commented 1 year ago

Describe

During the development of a trivial fix, it showed up the need to setup Jest for Nuxt functionalities, such like $fetch.

This may be avoided in case of cleaning up leftover logic https://github.com/rancher/dashboard/issues/9711 and stick to Vue lifecycle hooks.

NOTE: This is not an issue about async, rather a lack of the hook implementation in the vue-test-utils.

cnotv commented 4 months ago

Example case which may work in some cases (it did not for mine):

Thanks @torchiaf https://github.com/rancher/dashboard/pull/10493/files#diff-6321b8c64f34671df66c6092445640b8e9da0a2b208c02190f96896f7ab0cb3bR46-R53

  it('should show apps catalog', async() => {
    const wrapper = shallowMount(ClusterTools, mountOptions);

    await (ClusterTools as any).fetch.call(wrapper.vm);
    const cards = wrapper.find('[data-testid^="cluster-tools-app"]');

    expect(cards.exists()).toBe(true);
  });
cnotv commented 4 months ago

This issue may be solved with https://github.com/rancher/dashboard/issues/9711