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

Using setData with array does not trigger watchers or update the view #605

Closed
tbuteler opened this issue May 14, 2018 · 2 comments
Closed
Labels

Comments

@tbuteler
Copy link

Version

1.0.0-beta.16

Reproduction link

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

Steps to reproduce

Clone the repository, then run:

yarn install
yarn run tests

What is expected?

Component:

<template>
  <div id="app">
    <ul v-if="items.length > 0">
      <li v-for="item in items">
        {{ item }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
      loaded: false,
      items: []
    }
  },
  watch: {
    items () {
      this.loaded = true
    }
  }
}
</script>

Test:

import Vue from 'vue'
import { mount } from '@vue/test-utils'
import App from '../src/App.vue'

describe('App.vue', () => {
  it('array data triggers watchers', () => {
    const wrapper = mount(App)
    wrapper.setData({ items: ['Foo', 'Bar'] })
    expect(wrapper.vm.loaded).toBe(true)
    expect(wrapper.findAll('li').at(0).text()).toBe('Foo')
    expect(wrapper.findAll('li').at(1).text()).toBe('Bar')
  })
})

After doing setData I expected the HTML to be updated and the watcher (which sets loaded to true) to be run.

What is actually happening?

Although the wrapper.vm.items property yields what I just set, no updates are triggered on the wrapper and the tests fail.


Test passes in 1.0.0-beta.15.

@eddyerburgh
Copy link
Member

Could be related to #563 (comment)

@eddyerburgh
Copy link
Member

This was fixed in #604 . Although there is another bug with setData, if an array is nested

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

2 participants