Skip to content

Typescript error when use wrapper.classes().includes #684

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

Closed
Yawenina opened this issue Jun 6, 2018 · 4 comments
Closed

Typescript error when use wrapper.classes().includes #684

Yawenina opened this issue Jun 6, 2018 · 4 comments
Labels

Comments

@Yawenina
Copy link
Contributor

Yawenina commented Jun 6, 2018

Version

1.0.0-beta.16

Reproduction link

https://github.com/Yawenina/vue-test-utils-classes

Steps to reproduce

npm install

npm run serve

What is expected?

no error

What is actually happening?

In my test file, I write a test like this:

expect(wrapper.classes().includes('a')).toBe(false);

but when I ran npm run serve, typescript yield an error:

ERROR in vue-test-utils-classes/tests/unit/HelloWorld.spec.ts
10:30 Property 'includes' does not exist on type 'void | string[]'.
  Property 'includes' does not exist on type 'void'.
     8 |       propsData: { msg },
     9 |     });
  > 10 |     expect(wrapper.classes().includes('a')).toBe(false);
       |                              ^
    11 |   });
    12 | });
    13 |
Version: typescript 2.9.1

I read the source code and find the type definition of the classes() method is this:

classes(): Array<string> | void

Maybe because the return value could be void so it does not have a includes method.

When I change it to :

classes(): Array<string>

the error disappears and everything works ok.

@Yawenina Yawenina changed the title Typescript error when user wrapper.classes().includes Typescript error when use wrapper.classes().includes Jun 6, 2018
@eddyerburgh
Copy link
Member

Actually it never returns void, so the definition file is incorrect. Would you like to make a PR that removes the void? There are two definition files that need to be changed, one in packages/test-utils/ and one in packages/server-test-utils

@eddyerburgh eddyerburgh added the bug label Jun 6, 2018
@Yawenina
Copy link
Contributor Author

Yawenina commented Jun 6, 2018

Sure, I'd love to.

@Yawenina
Copy link
Contributor Author

Yawenina commented Jun 6, 2018

I didn't find classes definition in packages/server-test-utils, so I only changed it in packages/test-utils/.

PR #685 solves this issue.

@eddyerburgh
Copy link
Member

Ah sorry I forgot that we don't have Wrappers in server-test-utils 😅

Thanks for the PR 👍

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

No branches or pull requests

2 participants