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

Computed props are not reactive when using operation on primitive types, when they are used in template and the data, they are using, are setData() after mount/shallowMount #656

Copy link
Copy link
Closed
@trollepierre

Description

@trollepierre
Issue body actions

Version

1.0.0-beta.16

Reproduction link

http://google.com

Steps to reproduce

Computed props are not reactive when using operation on primitive types, when they are used in template and the data, they are using, are setData() after mount/shallowMount

Read the test to understand it

<template>
  <div>
    <child-component
      :workers="computedWorkers"
    />
  </div>
</template>

<script>
  import ChildComponent from './ChildComponent.vue'

  export default {
    name: 'Component',
    components: {
      ChildComponent,
    },
    data: () => ({
      workers: [],
    }),
    computed: {
      computedWorkers() {
        return this.workers.length === 0
      },
    },
  }
</script>

What is expected?

import { mount } from '@vue/test-utils'
import Component from './Component.vue'

describe('components | Component', () => {

  describe('template', () => {

    it('should have a computedWorkers set to false because not empty', () => {
      // Given
      const wrapper = mount(Component)

      // When
      wrapper.setData({ workers: [{}] })

      // Then
      expect(wrapper.vm.$data.workers).toEqual([{}])
      expect(wrapper.vm.computedWorkers).toEqual(false)
    })
  })
})

What is actually happening?

import { mount } from '@vue/test-utils'
import Component from './Component.vue'

describe('components | Component', () => {

  describe('template', () => {

    it('should have a computedWorkers set to false because not empty', () => {
      // Given
      const wrapper = mount(Component)

      // When
      wrapper.setData({ workers: [{}] })

      // Then
      expect(wrapper.vm.$data.workers).toEqual([{}])
      expect(wrapper.vm.computedWorkers).toEqual(true)
    })
  })
})

could you provide a template of CodePen, CodeSandbox if you want a link, please?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No 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.