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

Using nuxt3-class-component in Jest tests #2

Open
dubst3pp4 opened this issue Oct 18, 2023 · 0 comments
Open

Using nuxt3-class-component in Jest tests #2

dubst3pp4 opened this issue Oct 18, 2023 · 0 comments

Comments

@dubst3pp4
Copy link

dubst3pp4 commented Oct 18, 2023

At first thanks for this module. We're currently migrating a Nuxt2 app to Nuxt3, and as we're using the nuxt-property-decorator with class components, we're now able to use our components in Nuxt3 thanks to your module.

Unfortunately it doesn't work in our component tests using Jest. When Jest runs the component tests, the following errors occurs:

 FAIL  test/components/shared/CustomFieldForm.test.ts  
  ● Test suite failed to run
  
    Cannot find module 'nuxt-property-decorator' from 'components/shared/CustomFieldForm.vue'         

    Require stack:     
      components/shared/CustomFieldForm.vue                                                                                                                                                  
      test/components/shared/CustomFieldForm.test.ts                                                                                                                                         
                                                                                                                                                                                             
      176 |    * whether the component is in readonly mode or not 
      177 |    */ 
    > 178 |   @Prop({ 
          |
      179 |     default: false,
      180 |     type: Boolean                              
      181 |   }) 
                                         
      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)       
      at Object.<anonymous> (components/shared/CustomFieldForm.vue:178:33)                
      at Object.<anonymous> (test/components/shared/CustomFieldForm.test.ts:35:1)

I can assume that this errors happens, as the tests are not running in the Nuxt context. As you wrote:

Unlike the original nuxt-property-decorator, this package is implemented as a Nuxt module. This is because it uses defineNuxtComponent internally, which doesn't work outside of Nuxt compilation context.

Are you aware of a way to setup Jest so that I can also use the functionality in the component tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant