Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@tbuteler

Description

@tbuteler
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.