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

Computed property is not always updated #573

Closed
bponomarenko opened this issue May 2, 2018 · 1 comment · Fixed by #584
Closed

Computed property is not always updated #573

bponomarenko opened this issue May 2, 2018 · 1 comment · Fixed by #584
Labels

Comments

@bponomarenko
Copy link

Version

1.0.0-beta.15

Reproduction link

https://github.com/bponomarenko/vue-test-utils-issue

Steps to reproduce

Clone repository. Then run:

npm install
npm run test

What is expected?

All unit tests pass.

Component:

<template>
  <div id="app">
    {{ stringified }}
  </div>
</template>

<script>
export default {
  props: {
    collection: {
      type: Array,
      default: () => [],
    }
  },
  data: () => ({
    data: ''
  }),
  computed: {
    stringified() {
      return this.collection.join(',');
    }
  },
  watch: {
    collection: 'execute',
  },
  methods: {
    execute() {
      this.data = this.stringified;
    }
  }
}
</script>

Test:

import { shallow } from '@vue/test-utils'
import App from '@/App.vue'

describe('App.vue', () => {
  it('renders props.msg when passed', () => {
    const wrapper = shallow(App);
    expect(wrapper.vm.stringified).toEqual('');
    expect(wrapper.vm.data).toEqual('');

    wrapper.setProps({ collection: [1, 2, 3] });
    expect(wrapper.vm.stringified).toEqual('1,2,3');
    expect(wrapper.vm.data).toEqual('1,2,3');

    wrapper.vm.collection.push(4, 5);
    expect(wrapper.vm.stringified).toEqual('1,2,3,4,5');
    expect(wrapper.vm.data).toEqual('1,2,3,4,5');
  });
});

It is expected, that computed property will be updated as soon as collection property changed.

What is actually happening?

Computed property is not updated.


When component is rendered on the page – computed property is properly updated on "collection" property mutation.

Might be related to previously fixed #502

@eddyerburgh
Copy link
Member

This has been fixed and will be released in the next version 👍

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

Successfully merging a pull request may close this issue.

2 participants