Skip to content

Commit 9962e5b

Browse files
committed
tests: add test for latest <script setup>
1 parent e4d95a3 commit 9962e5b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

tests/components/ScriptSetup.vue

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script setup lang="ts">
2+
// imported components are also directly usable in template
3+
import { ref } from 'vue'
4+
5+
// write Composition API code just like in a normal setup()
6+
// but no need to manually return everything
7+
const count = ref(0)
8+
const inc = () => { count.value++ }
9+
</script>
10+
11+
<template>
12+
<button @click="inc">{{ count }}</button>
13+
</template>

tests/features/sfc.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import { mount } from '../../src'
22
import Hello from '../components/Hello.vue'
3+
import ScriptSetup from '../components/ScriptSetup.vue'
34

45
describe('sfc', () => {
56
it('mounts an sfc via vue-test-transformer', () => {
67
const wrapper = mount(Hello)
78
expect(wrapper.find('#msg').text()).toBe('Hello world')
89
})
10+
11+
// rfc: https://github.com/vuejs/rfcs/pull/228
12+
it('works with <script setup> (as of Vue 3.0.3)', async () => {
13+
const wrapper = mount(ScriptSetup)
14+
await wrapper.find('button').trigger('click')
15+
expect(wrapper.html()).toContain('1')
16+
})
917
})

0 commit comments

Comments
 (0)