Skip to content

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

@Yawenina

Description

@Yawenina

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions