question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing Typescript types for `vueWrapper` after 10.0 migration

See original GitHub issue

Current behavior

My project was using component testing before v10.

This is the code I’m using to get the Vue wrapper with type hinting.

    cy.get("button")
      .click()
      .get<Cypress.Cypress["vueWrapper"]>("@wrapper")
      .should((wrapper) => {
        expect(wrapper.emitted().click).to.have.length(1);
      });

After the migration, my vue-tsc command spat out these errors all over the place:

error TS2339: Property 'emitted' does not exist on type 'JQuery<VueWrapper<ComponentPublicInstance<{}, {}, {}, {}, {}, {}, {}, {}, false, ComponentOptionsBase<any, any, any, any, any, any, any, any, any, {}>>>>'.

13         expect(wrapper.emitted().click).to.have.length(1);

I removed the @cypress/vue dependency from my project as instructed by this part of the Migration Guide: https://docs.cypress.io/guides/references/migration-guide#Component-Testing-Changes

This caused the @vue/test-utils package to disappear from my dependency tree.

I have fixed this problem in my project by installing @vue/test-utils in my project, and adding it to my tsconfig.json types.

Desired behavior

The Typescript types from @vue/test-utils should ship with cypress for Vue projects. I don’t want to install the dependency just for the Typescript types.

Test code to reproduce

Starting with a clean Typescript + Vue 3 + Cypress 10 setup, you should be able to reproduce this error by including the following in any chain:

.get<Cypress.Cypress["vueWrapper"]>("@wrapper")
.should((wrapper) => {
  expect(wrapper.emitted().click).to.have.length(1);
});

Cypress Version

10.0.2

Other

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lmiller1990commented, Jun 3, 2022

Thanks for the detailed bug report. I’ve seen this in a fresh project just now, too, and came to the same conclusion. The problem is we are bundling Test Utils with cypress/vue, as part of the binary (the thing you get when you do npm install cypress which is just a big JS blob - we don’t include the types.

I think what we will likely need to do is also generate the types as part of the build step, and stick them here: https://github.com/cypress-io/cypress/tree/develop/cli/types with the other types.

Glad that you found the work around (installing @vue/test-utils). This is definitely not ideal, though, and something we will fix in the near future (this month).

As an aside, if you have any other suggestions for component testing with Vue, feel free to open an issue or discussion - and thanks a lot for trying out Cypress 10 so early, and the updated Component Testing!

1reaction
lmiller1990commented, Jul 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing Typescript types for `vueWrapper` after 10.0 migration
My project was using component testing before v10. This is the code I'm using to get the Vue wrapper with type hinting. cy.get( ......
Read more >
TypeScript error when using data/props mounting option #194
Property 'props' is missing in type 'ComponentOptionsBase<{}, any, any, any, any, any, any, any, string, {}> & ThisType<any>' but required in ...
Read more >
Getting error in unit test from new vue 3 project generated by CLI
Type 'EmitsOptions' is not assignable to type 'string[]'. Type 'Record<string, ((...args: any[]) => any) | null>' is missing the following ...
Read more >
TypeScript - Cypress Documentation
The "types" will tell the TypeScript compiler to only include type definitions from Cypress. This will address instances where the project also uses ......
Read more >
How to use Vue 3 with TypeScript - LogRocket Blog
Build an example Vue app in TypeScript with class-based components ... For detailed information on how to migrate your existing Vue projects ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found