question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setProps does not update a data property

See original GitHub issue

Version

1.0.0-beta.11

Reproduction link

https://github.com/iraklisg/vue-test-utils-example

Steps to reproduce

  1. Clone the repo
  2. npm install
  3. npm run test or npm run watch

What is expected?

The test should pass

What is actually happening?

The setProps method does not update the data property


If we mount the component with options (propsData), instead of using the setProps() method, the test will pass green

wrapper = mount(Foo, {
    propsData: {
        dataFoo: "foo"
    } 
});

<!-- generated by vue-issues. DO NOT REMOVE -->

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
dennythecodercommented, Mar 21, 2018

@iraklisg, Using setProps() does not re-instantiate the component/vm/wrapper. Instead, it’s similar to when the component’s parent (component or app) modifies the prop value and triggers an update. Update from the documentation appears to be referring to the normal reactivity in Vue.

setProps is found here: https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/wrapper.js#L495

forces update might be better worded though. I don’t see $forceUpdate being called.

0reactions
sandranrivascommented, Feb 3, 2021

hey, after many hours of looking, I got an answer of how to workaround this. https://stackoverflow.com/a/66029922/12237505

Read more comments on GitHub >

github_iconTop Results From Across the Web

this.setProps doesnt automatically update - Stack Overflow
The property updates after the function ends and next time I called my function myProperty is the new value but does anyone know...
Read more >
setProps - Vue Test Utils
Sets Wrapper vm props and forces update. WARNING. setProps should be called only for top-level component, mounted by mount or shallowMount.
Read more >
setProps(nextProps) · Enzyme - GitHub Pages
A method that sets the props of the root component, and re-renders. Useful for when you are wanting to test how the component...
Read more >
[Solved]-How do I use @vue/test-utils to setProps and have them ...
Your component is not expecting any props. When you mounting your component you are setting component's data property. And if you want to...
Read more >
Update Props | Testing Library
This is an example of how to update the props of a rendered component. ... same component on the same container does not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found