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

Re-render does not occur synchronously when reactive data is changed in mounted life-cycle hook #1035

Closed
Aaron-Pool opened this issue Nov 21, 2018 · 2 comments · Fixed by #1062

Comments

@Aaron-Pool
Copy link

Version

1.0.0-beta.25

Reproduction link

https://github.com/Aaron-Pool/vue-test-utils-jest-example

Steps to reproduce

  1. clone reproduction repo
  2. Run yarn
  3. run yarn jest

What is expected?

Test should pass, because reactive data changed in the mount component, so the scoped slot function should have been called again on re-render.

What is actually happening?

No re-render occurs, even though the data updates as expected.


I assume this has something to do with async vs. sync paradigm that is happening in the test-utils.

It works correctly if I run the test like so:

it('should initialize with dimension data', done => {
  const mockSlot = jest.fn();
  const comp = factory(mockSlot);
  comp.vm.$nextTick(() => {
    expect(mockSlot.mock.calls).toEqual([[{ width: null, height: null }], [{ width: 500, height: 500 }]]);
    done();
  })
});
@Aaron-Pool Aaron-Pool changed the title Rer-ender does not occur synchronously when reactive data is changed in mounted life-cycle hook Re-render does not occur synchronously when reactive data is changed in mounted life-cycle hook Nov 27, 2018
@pgoshulak
Copy link

recognizing this doesn't directly address the synchronicity issue, I found a slightly more elegant temporary workaround is to make the test async, then run as:

const comp = factory(mockSlot)
await comp.vm.$nextTick()
expect(........)

@Aaron-Pool
Copy link
Author

@pgoshulak Thanks for the heads up on that 👍 I may implement that as a stopgap as well, to make things cleaner.

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

Successfully merging a pull request may close this issue.

3 participants