Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Dynamic imports not present #1198

Closed
segundaestrella opened this issue Mar 27, 2019 · 6 comments
Closed

Fix for Dynamic imports not present #1198

segundaestrella opened this issue Mar 27, 2019 · 6 comments

Comments

@segundaestrella
Copy link

Version

1.0.0-beta.29

Reproduction link

https://github.com/vuejs/vue-test-utils/blob/dev/CHANGELOG.md

Steps to reproduce

What is expected?

In the latest version is expected to be included the fix
#864

What is actually happening?

The fix #864 for dynamic imports seems lost.

On the repo changelog is listed in the release 1.0.0-beta.22 (2018-07-29)
https://github.com/vuejs/vue-test-utils/blob/dev/CHANGELOG.md

On the vue-test-utils package changelog is not listed
https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/CHANGELOG.md

And with the latest release a test with dynamic import still fails

      [Vue warn]: Failed to resolve async component: function vsMobileCalendarOverview() {
        return import('./MobileCalendarOverview.vue');
      }
      Reason: Error: Not supported
    console.error node_modules/vue/dist/vue.runtime.common.js:589
      [Vue warn]: Failed to resolve async component: function vsMobileCalendarDaily() {
        return import('./MobileCalendarDaily.vue');
      }
      Reason: Error: Not supported
@eddyerburgh
Copy link
Member

Hi I need a reproduction to help with this issue

@RyanHavoc
Copy link

Is there any progress on this issue? I've just encountered the same problem:

    [Vue warn]: Failed to resolve async component: () => {
          /* istanbul ignore next */
          cov_u5d2hd5dv.f[20]++;
          cov_u5d2hd5dv.s[24]++;
          return import('Icons/GithubCircle');
        }
    Reason: Error: Not supported

@RyanHavoc
Copy link

I found a solution. Needed to update my .bablerc to include:

  "env": {
    "test": {
      "plugins": ["dynamic-import-node"]
    }
  }

@alexxiyang
Copy link

Use mount + stubs instead of shallowMount

For example, Parent component lazy load Child component

<template>
  <div>
    Parent
    <Child />
  </div>
</template>

<script>

export default {
  components: {
    Child: () => import('./Child')
  }
}
</script>

Step 1. Change shallowMount into mount in unit tests

const wrapper = mount(Parent)

Step 2. Add stubs option to mount

const wrapper = mount(Parent, {
      stubs: {
        Child: true
    }
  })

The child component will be mount as <child-stub></child-stub> like we are using shallowMount.

@sumerokr
Copy link

sumerokr commented Aug 23, 2020

@alexxiyang hey, thanks for this tip above!
But it looks, like there is no chance to find such stub by component reference via findComponent method

I mean

import Child from 'some'/path';
...
wrapper.findComponent(Child); // will return an error ErrorWrapper.

The problem is gone, when Child imported as a regular (not async) component in Parent.

As workaround I use wrapper.find('child-stub'), but it feels bad.

@ebisbe
Copy link
Collaborator

ebisbe commented Feb 15, 2023

#1564 (comment)

@ebisbe ebisbe closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants