|
| 1 | +/******************************************************************************* |
| 2 | + * |
| 3 | + * Copyright (c) 2022 - 2023. |
| 4 | + * Haixing Hu, Qubit Co. Ltd. |
| 5 | + * |
| 6 | + * All rights reserved. |
| 7 | + * |
| 8 | + ******************************************************************************/ |
| 9 | +import { mount } from '@vue/test-utils'; |
| 10 | +import { nextTick } from 'vue'; |
| 11 | +import { Component, toVue } from '../src'; |
| 12 | + |
| 13 | +function AddMessage(target, context) { |
| 14 | + // add a new field to the target class |
| 15 | + target.prototype.message = 'Hello'; |
| 16 | +} |
| 17 | + |
| 18 | +@Component({ |
| 19 | + template: '<div><div id="value">{{ value }}</div><div id="message">{{ message }}</div></div>', |
| 20 | +}) |
| 21 | +@AddMessage |
| 22 | +class Test { |
| 23 | + value = 123; |
| 24 | +} |
| 25 | +const TestComponent = toVue(Test); |
| 26 | + |
| 27 | + |
| 28 | +describe('bug #5', () => { |
| 29 | + test('Should handle the class field added to the prototype of the class', async () => { |
| 30 | + const w1 = mount(TestComponent); |
| 31 | + const v1 = w1.vm; |
| 32 | + expect(v1.value).toBe(123); |
| 33 | + expect(v1.message).toBe('Hello'); |
| 34 | + const w2 = mount(TestComponent); |
| 35 | + const v2 = w2.vm; |
| 36 | + expect(v2.value).toBe(123); |
| 37 | + expect(v2.message).toBe('Hello'); |
| 38 | + v2.message = 'World'; |
| 39 | + expect(v1.message).toBe('Hello'); |
| 40 | + expect(v2.message).toBe('World'); |
| 41 | + await nextTick(); |
| 42 | + const m1 = w1.get('#message'); |
| 43 | + const m2 = w2.get('#message'); |
| 44 | + expect(m1.text()).toBe('Hello'); |
| 45 | + expect(m2.text()).toBe('World'); |
| 46 | + }); |
| 47 | +}); |
0 commit comments