Skip to content

Commit

Permalink
Fixing prototype methods being discarded when using setData
Browse files Browse the repository at this point in the history
  • Loading branch information
rory-instil committed Aug 22, 2023
1 parent 83855a0 commit 6671b01
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions tests/setData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ describe('setData', () => {
it('should retain prototype methods for constructed objects when calling setData', async () => {
const expectedResult = 'success!'
class TestClass {
getResult() {
constructor(readonly name: string) {}
getResult(): string {
return expectedResult
}
}
Expand All @@ -227,22 +228,22 @@ describe('setData', () => {
defineComponent({
template: '<div/>',
data() {
return { value: new TestClass() }
return { value: new TestClass('test1') }
},
methods: {
getResult() {
return this.value.getResult()
return `${this.value.name}: ${this.value.getResult()}`
}
}
})
)

expect(wrapper.vm.getResult()).toStrictEqual(expectedResult)
expect(wrapper.vm.getResult()).toStrictEqual(`test1: ${expectedResult}`)

await wrapper.setData({
value: new TestClass()
value: new TestClass('test2')
})

expect(wrapper.vm.getResult()).toStrictEqual(expectedResult)
expect(wrapper.vm.getResult()).toStrictEqual(`test2: ${expectedResult}`)
})
})

0 comments on commit 6671b01

Please sign in to comment.