Skip to content

Wrapper from vue-test-utils not exposed? #46

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
gchenglevi opened this issue Jun 21, 2019 · 6 comments
Closed

Wrapper from vue-test-utils not exposed? #46

gchenglevi opened this issue Jun 21, 2019 · 6 comments

Comments

@gchenglevi
Copy link

Hi, I wanted to call something like wrapper.isVueInstance() like I would with vue-test-utils. Looks like this wouldn't be possible in this library? Thanks.

@afontcu
Copy link
Member

afontcu commented Jun 22, 2019

Hi! 👋 and thanks for your question.

Vue Testing Library tries to follow the Testing Library Guiding Principle. Since we are trying to focus on rendering components instead of dealing with component instances, it wouldn't make much sense to provide a tool that helps testing you the exact opposite - if a given wrapper is a Vue instance.

That's the reason behind not providing such method.

In Vue Testing Library world, I'd just render the component and assert that the "initial state" is already there - the default strings, values, and so on.

Hope I helped!

@gchenglevi
Copy link
Author

Ah okay, so my use case is asserting that for my dumb component that an event is emitted on a certain click. Would you say it is good practice to mix tests importing mount from vue-test-utils and tests with this library in the same component test file?

@afontcu
Copy link
Member

afontcu commented Jun 23, 2019

Check out the simple button test example, because it looks quite similar to your use case:

  1. render the component (I'd go with Vue Testing Library render())
  2. get the clickable element
  3. fire a click event
  4. assert the event was emitted

hope it helps!

@gchenglevi
Copy link
Author

Oh thanks! I missed the emitted method. However, if there would be other cases in the future where I wanted to use a method that isn't exposed, it sounds like it wouldn't be good practice to mix the two libraries.

@afontcu
Copy link
Member

afontcu commented Jun 25, 2019

VTL exposes a render() method that contains DOM Testing Library queries + some vue-test-utils methods too: https://testing-library.com/docs/vue-testing-library/api So, in theory, you are mixing both libraris.

The idea is that by using VTL you get the tools to test your components far from implementation details, so if you feel the urge to use a non-exposed method, I believe you'll find an available one that suits your needs. If not, let us know! ;)

Thanks for your questions! Feel free to open up another issue if anything is unclear while using VTL 😄

@afontcu afontcu closed this as completed Jun 25, 2019
@Blindpupil
Copy link

In my case the component expects data from the store in deeply nested modules. I want to access the vm to set the store data that I need. I can do it via the options parameter when the data is in the root, but I'm having a lot of issues making it work when the data is in a deeply nested module

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

3 participants