testing-library / vue-testing-library

🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
http://testing-library.com/vue
MIT License
1.08k stars 110 forks source link

Problems with Vue and TypeScript #190

Closed iandevlin closed 3 years ago

iandevlin commented 3 years ago

Please provide some detailed documentation on how one can set this up to work with TypeScript. The current documentation says that "Vue Testing Library does not require any configuration to be used." but this does not appear to be the case.

At the moment no matter what I try (even examples that exist in your documentation) TypeScript constantly complains about TS2339: Property X does not exist on type 'HTMLElement', where X is any one of the functions such as toBeVisible', 'toHaveClass etc.

For example, the following code throws this error:

import { render } from '@testing-library/vue';
import Component from '@/components/MyComponent/MyComponent.vue';

test('Component Test', async () => {
    const { getByTestId } = render(Component);
    expect(getByTestId('test-id').toHaveClass('test-class'));
});

(I have also tried adding import '@testing-library/jest-dom'; as I read something somewhere that indicates that one needs to do this, but it had no effect).

Now I may of course be missing something obvious, and I apologise if I am, but I have spent a number of hours trying to get this to work, to no avail.

Is there some extra configuration that I need to add somewhere? If so, where?

Any help would be appreciated. Thanks in advance.

afontcu commented 3 years ago

Hi!

Looks like the issue is related to jest-dom, not Vue Testing Library. As stated in their docs, there's no additional config to work with TS other than load jset-dom from a .ts file. Can you double check this is the case?

Thanks

iandevlin commented 3 years ago

Hello! Well crap, I apologise for posting here if it's clearly the wrong place. And yes, I have done what they say there, but to no avail. I will annoy them about it now, my apologies again and thanks for the help regardless!

afontcu commented 3 years ago

No prob! Thanks :)