Skip to content

Commit 9c1caca

Browse files
committed
测试: 完善测试
1 parent 26e1930 commit 9c1caca

File tree

2 files changed

+63
-21
lines changed

2 files changed

+63
-21
lines changed

test/decorator/computed.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import '@abraham/reflection'
2+
import { expect, test } from 'vitest'
3+
import { Computed, Mut, VueComponent } from 'vue3-oop'
4+
import { mount } from '@vue/test-utils'
5+
6+
class CountComponent extends VueComponent {
7+
@Mut() count = 1
8+
9+
@Computed()
10+
get double() {
11+
return this.count * 2
12+
}
13+
14+
render() {
15+
return (
16+
<div>
17+
<p>{this.double}</p>
18+
</div>
19+
)
20+
}
21+
}
22+
23+
test('Computed decorator should work', async () => {
24+
// @ts-ignore
25+
const wrapper = mount(CountComponent)
26+
const vm = wrapper.vm as unknown as CountComponent
27+
28+
const p = wrapper.get('p')
29+
expect(p.text()).toContain('2')
30+
vm.count++
31+
await vm.$nextTick()
32+
expect(p.text()).toContain('4')
33+
})

test/decorator.test.tsx renamed to test/decorator/mut.test.tsx

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,43 @@ const debounceRef: CustomRefFactory<any> = (track, trigger) => {
2828
const delay = (timeout: number) =>
2929
new Promise((resolve) => setTimeout(resolve, timeout))
3030

31-
test('Mut decorator', async () => {
32-
class CountComponent extends VueComponent {
33-
@Mut() count = 1
34-
// shallow ref
35-
@Mut(true) obj = { count: 1 }
36-
// custom ref
37-
@Mut(debounceRef) count1 = 1
31+
class CountComponent extends VueComponent {
32+
@Mut() count = 1
33+
// shallow ref
34+
@Mut(true) obj = { count: 1 }
35+
// custom ref
36+
@Mut(debounceRef) count1 = 1
3837

39-
render() {
40-
return (
41-
<div>
42-
<p onClick={() => this.count++}>{this.count}</p>
43-
<div id="shallow" onClick={() => this.obj.count++}>
44-
{this.obj.count}
45-
</div>
46-
<div id="custom" onClick={() => this.count1++}>
47-
{this.count1}
48-
</div>
38+
render() {
39+
return (
40+
<div>
41+
<p onClick={() => this.count++}>{this.count}</p>
42+
<div id="shallow" onClick={() => this.obj.count++}>
43+
{this.obj.count}
4944
</div>
50-
)
51-
}
45+
<div id="custom" onClick={() => this.count1++}>
46+
{this.count1}
47+
</div>
48+
</div>
49+
)
5250
}
51+
}
52+
53+
test('Mut decorator should work', async () => {
5354
// @ts-ignore
5455
const wrapper = mount(CountComponent)
55-
const vm = wrapper.vm as unknown as CountComponent
5656

5757
const p = wrapper.get('p')
5858
expect(p.text()).toContain('1')
5959
await p.trigger('click')
6060
expect(p.text()).toContain('2')
61+
})
62+
63+
test('mut: shallow ref', async () => {
64+
// @ts-ignore
65+
const wrapper = mount(CountComponent)
66+
const vm = wrapper.vm as unknown as CountComponent
6167

62-
// shallow ref
6368
const shallow = wrapper.get('#shallow')
6469
expect(shallow.text()).toContain('1')
6570
await shallow.trigger('click')
@@ -69,7 +74,11 @@ test('Mut decorator', async () => {
6974
await vm.$nextTick()
7075
console.log(shallow.text())
7176
expect(shallow.text()).toContain('2')
77+
})
7278

79+
test('mut: custom ref', async () => {
80+
// @ts-ignore
81+
const wrapper = mount(CountComponent)
7382
// custom ref
7483
const custom = wrapper.get('#custom')
7584
expect(custom.text()).toContain('1')

0 commit comments

Comments
 (0)