Skip to content

Cannot set data properties on a component #118

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
EvanBurbidge opened this issue Jan 9, 2020 · 7 comments
Closed

Cannot set data properties on a component #118

EvanBurbidge opened this issue Jan 9, 2020 · 7 comments

Comments

@EvanBurbidge
Copy link

Describe the bug
From what i've heard this library is a wrapper around @vue/test-utils, one of the most handy functions I find with that library is the wrapper.setData() method. I cannot do that with this library.

Expected behavior

When rendering a component I should be able to set the data attributes on rendering.

const { debug } = render(Component, {props: {}, data: { someProperty: 'string' } } );
debug(); // see string in the template etc.

Related information:

  • @testing-library/vue version: 4.1.0
  • Vue version: 2.6.10
  • node version: 10.16.0
  • npm (or yarn) version: 6.9.0
@EvanBurbidge EvanBurbidge added the bug Something isn't working label Jan 9, 2020
@afontcu afontcu removed the bug Something isn't working label Jan 9, 2020
@afontcu
Copy link
Member

afontcu commented Jan 9, 2020

Hi! Thanks for filling in the issue.

This is not a bug, since VTL aims for providing the tools that allow you to interact with your components as the end user or the developer would do – neither of them would be able to directly modify the internal data from a component, and this is why VTL does not exposed such method.

What's your use case? Maybe we can figure it out 🙌

@EvanBurbidge
Copy link
Author

@afontcu In my component there are some api calls within methods on the component. These set certain data attributes, i'm not sure how to mock them as they are hardcoded into the component itself. This is why i'm using the setData method from vue-test-utils in order to set the values.

@afontcu
Copy link
Member

afontcu commented Jan 9, 2020

You should mock you API calls – https://afontcu.dev/testing-api-calls/

So you can test without hitting a back end, and also reassure that you're getting the desired output from the API call.

@EvanBurbidge
Copy link
Author

In that example the api calls are in a separate file. My api calls are written into the vue component itself.

@afontcu
Copy link
Member

afontcu commented Jan 9, 2020

If a test is hard to write, it usually means the component is doing too much, or that it is too coupled. You might benefit from removing responsibilities from it to other parts of your system.

Anyway, you can easily mock axios (or fetch or any other service) the same way!

@EvanBurbidge
Copy link
Author

This is true, might refactor the component! Nice one :)

@afontcu
Copy link
Member

afontcu commented Jan 9, 2020

Thanks for commenting, though! :) Feel free to raise any other issue or ask any question in our Spectrum chat: https://spectrum.chat/testing-library

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

2 participants