Skip to content

Commit 9533074

Browse files
committed
tests: add more thorough tests for class component
1 parent 042f935 commit 9533074

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tests/components/ClassComponent.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<div class="hello">
3-
<h1>{{ computedMsg }}</h1>
3+
<h1 data-computed>{{ computedMsg }}</h1>
4+
<h2 data-props>{{ msg }}</h2>
5+
<h3 data-methods>{{ dataText }}</h3>
46
<button @click="changeMessage('Hello')" />
57
</div>
68
</template>
@@ -13,13 +15,13 @@ import { Options, Vue } from 'vue-class-component'
1315
}
1416
})
1517
export default class ClassComponent extends Vue {
16-
dataText: string
18+
dataText: string = ''
1719
get computedMsg(): string {
1820
return `Message: ${(this.$props as any).msg}`
1921
}
2022
2123
changeMessage(text: string): void {
22-
this.dataText = text
24+
this.dataText = 'Updated'
2325
}
2426
}
2527
</script>

tests/features/classComponent.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ describe('class component', () => {
9393
expect(wrapper.vm.b).toBe(3)
9494
})
9595

96-
it('works with shallow mount and SFC', async () => {
96+
it.only('works with shallow mount and SFC', async () => {
9797
const wrapper = mount(ClassComponent, {
98+
props: {
99+
msg: 'Props Message'
100+
},
98101
shallow: true
99102
})
103+
expect(wrapper.get('[data-computed]').text()).toBe('Message: Props Message')
104+
expect(wrapper.get('[data-props]').text()).toBe('Props Message')
100105
await wrapper.get('button').trigger('click')
101-
expect(wrapper.get('h1').text()).toMatch('Hello')
106+
expect(wrapper.get('[data-methods]').text()).toBe('Updated')
102107
})
103108
})

0 commit comments

Comments
 (0)