Skip to content
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

setProps doesn't update props in some circumstances #738

Closed
TheCycoONE opened this issue Jun 19, 2018 · 16 comments
Closed

setProps doesn't update props in some circumstances #738

TheCycoONE opened this issue Jun 19, 2018 · 16 comments
Labels

Comments

@TheCycoONE
Copy link

Version

1.0.0-beta.19

Reproduction link

https://codesandbox.io/s/1k6y65wp4

Steps to reproduce

Create a component, like the one in the above reproduction, with multiple properties that are watched.
It is important that the watch function reads one of the properties (i.e. if you remove that switch statement from my test case the problem doesn't happen.)
Create a test for that component, call setProps on the property that is read in the watch.

What is expected?

The property should be updated, the component should react to the updated property

What is actually happening?

The property is never updated. props() shows the old value.

Note: this is a regression, it worked correctly in 1.0.0-beta.16 (I did not try other versions)

jbeezley added a commit to Kitware/resonantgeo that referenced this issue Jun 21, 2018
This provides more flexibility in using the components compared to
accessing the `$parent` component directly.  This is particularly
relevant because newer versions of `@vue/test-utils` broke how we were
injecting the parent components in unit testing.

Note: This also updates `@vue/test-utils`, but not to the latest version
because there is a bug since `beta-18` causing props not to be updated.
This may (or may not) be related to the following issue:

vuejs/vue-test-utils#738
jbeezley added a commit to Kitware/resonantgeo that referenced this issue Jun 21, 2018
This provides more flexibility in using the components compared to
accessing the `$parent` component directly.  This is particularly
relevant because newer versions of `@vue/test-utils` broke how we were
injecting the parent components in unit testing.

Note: This also updates `@vue/test-utils`, but not to the latest version
because there is a bug since `beta-18` causing props not to be updated.
This may (or may not) be related to the following issue:

vuejs/vue-test-utils#738
jbeezley added a commit to Kitware/resonantgeo that referenced this issue Jun 21, 2018
This provides more flexibility in using the components compared to
accessing the `$parent` component directly.  This is particularly
relevant because newer versions of `@vue/test-utils` broke how we were
injecting the parent components in unit testing.

Note: This also updates `@vue/test-utils`, but not to the latest version
because there is a bug since `beta-18` causing props not to be updated.
This may (or may not) be related to the following issue:

vuejs/vue-test-utils#738
@eddyerburgh
Copy link
Member

Sorry, this is another problem with how we've implemented synchronous renders.

There's a PR open to fix this by adding an async option to Vue—vuejs/vue#8240.

For the moment, the workaround is to set the sync mounting option to false and use Vue.nextTick/ setTimeout to await DOM updates (like you're doing):

test('use Vue.nextTick', (done) => {
  const wrapper = mount(TestComponent, { sync: false })
  wrapper.trigger('click')
  Vue.nextTick(() => {
    expect(wrapper.text()).toBe('updated')
    done()
  })
})

@TheCycoONE
Copy link
Author

TheCycoONE commented Jul 3, 2018

Setting sync false and waiting for Vue.nextTick doesn't appear to work around the countingAlgo prop not updating case that started happening after updating from beta 16 to beta 19.

It does workaround the DOM not updating when setProp({value: 42}) is called which was needed in 16 as well.

@HcySunYang
Copy link
Member

@TheCycoONE @eddyerburgh
setProps does not work in [email protected], behaves like this issue, but works fine in the latest version of vue.

@TheCycoONE
Copy link
Author

@HcySunYang I am on vue 2.5.16

@agriffis
Copy link

@TheCycoONE I'm hitting this too. What are you doing as a workaround?

@TheCycoONE
Copy link
Author

Unfortunately I haven't found a workaround yet. For now I'm .skipping those tests.

@agriffis
Copy link

I guess npm i -D @vue/[email protected] works. 18, 19 and 20 are broken.

agriffis added a commit to agriffis/vue-test-utils that referenced this issue Jul 12, 2018
@agriffis
Copy link

It's hard to pin this bug down. I finally found a minimal failing test: updating a prop that is referenced through a chain of computed and lifecycle hook. I created #820 with that test case.

With that specific configuration, here's the table:

  sync: true sync: false
1.0.0-beta.17 works works
1.0.0-beta.18 works works
1.0.0-beta.19 broken works
1.0.0-beta.20 broken works

I think that table changes slightly depending on the exact component configuration, but that's what I found for the minimal test case.

@eddyerburgh
Copy link
Member

Thanks @agriffis .

This will be fixed when Vue 2.6 is released. Until then, you will need to run tests with sync set to false.

@jcupps
Copy link

jcupps commented Jul 17, 2018

FWIW sync = false and Vue.nextTick/setTimeout doesn't seem to work for my use case either :(

@PierreTurnbull
Copy link

PierreTurnbull commented Dec 16, 2019

Hello, I have this bug on Vue 2.6.11. When using wrapper.setProps, the expectation that comes after doesn't work, unless I enclosed it in nextTick. Note that it seems like I don't need to set sync to false when mounting my component for the test to work.

@Sefriol
Copy link

Sefriol commented May 19, 2020

Hello, I have this bug on Vue 2.6.11. When using wrapper.setProps, the expectation that comes after doesn't work, unless I enclosed it in nextTick. Note that it seems like I don't need to set sync to false when mounting my component for the test to work.

Noticed the same with @vue/cli 4.3.1 and Vue 2.6.10

@dobromir-hristov
Copy link
Contributor

In my testing I have noticed it works mostly after I await nextTick. The current versions of VTU no longer have sync: false. Latest VTU version you can just await setProps(), should work :)

@Sefriol
Copy link

Sefriol commented May 20, 2020

I think await setProps does pass the checks when trying to get the prop values etc, but it fails to update the html/text and fails .contains checks until you use await nextTick().

@dobromir-hristov
Copy link
Contributor

setProps returns nextTick if I am not mistaking :/

@manonheine
Copy link

await nextTick() doesn't do it for me, the props are supposedly updated (as seen from console.log) but have no effect whatsoever on the functions that are called after.
My current work around is to re-shallowMount the component with updated props in propsData in the test, then it suddenly works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants