Skip to content

Computed property not updating when based on new state object property and used by template #798

@Mardoxx

Description

@Mardoxx

Version

1.0.0-beta.20

Reproduction link

#798

Steps to reproduce

Add this to test/specs/wrapper/setData.spec.js

it('should append a new property to an object when the new property is referenced by a template', () => {
  const TestComponent = {
    data: () => ({
      anObject: {
        propA: 'a',
        propB: 'b'
      }
    }),
    computed: {
      anObjectKeys() {
        return Object.keys(this.anObject).join(',')
      }
    },
    template: `<div>{{ anObjectKeys }}</div>`
  }
  const wrapper = mountingMethod(TestComponent)
  wrapper.setData({
    anObject: {
      propC: 'c'
    }
  })

  expect(wrapper.vm.anObject.propA).to.equal('a')
  expect(wrapper.vm.anObject.propB).to.equal('b')
  expect(wrapper.vm.anObject.propC).to.equal('c')
  expect(wrapper.vm.anObjectKeys).to.equal('propA,propB,propC')
  expect(wrapper.html()).to.equal('<div>propA,propB,propC</div>')
})

What is expected?

expect(wrapper.vm.anObjectKeys).to.equal('propA,propB,propC')

What is actually happening?

The computed property is not being updated, when setData() is being called.


If you remove the reference to anObjectKeys from the template, it works fine - besides the last assertion, obviously.

Also fails in dev @ 1ee03ac

See also, #565

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