Skip to content

Commit 60ef3c7

Browse files
committed
Merge branch 'master' of github.com:vuejs/vue-jest
2 parents 1354116 + 800b6f4 commit 60ef3c7

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

Diff for: e2e/3.x/typescript/src/components/ScriptSetup.vue

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<button @click="increase">Count: {{ num }}</button>
3+
<Basic />
4+
<span>{{ msg! }}</span>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import Basic from './Basic.vue'
9+
import { ref } from 'vue'
10+
11+
const num = ref(5)
12+
const greet = () => console.log('greet')
13+
const increase = () => {
14+
greet()
15+
num.value++
16+
}
17+
const msg = 'hello world'
18+
</script>

Diff for: e2e/3.x/typescript/src/test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createApp, h } from 'vue'
22

33
import Basic from '@/components/Basic.vue'
4+
import ScriptSetup from '@/components/ScriptSetup.vue'
45

56
function mount(Component: any) {
67
document.getElementsByTagName('html')[0].innerHTML = ''
@@ -21,3 +22,9 @@ test('processes .vue files', () => {
2122
'Welcome to Your Vue.js App'
2223
)
2324
})
25+
26+
test('supports <script setup>', () => {
27+
mount(ScriptSetup)
28+
expect(document.body.outerHTML).toContain('Count: 5')
29+
expect(document.body.outerHTML).toContain('Welcome to Your Vue.js App')
30+
})

Diff for: packages/vue3-jest/lib/process.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ function processTemplate(descriptor, filename, config) {
9595
// but this needs the `isTS` option of the compiler.
9696
// We could let users set it themselves, but vue-loader and vite automatically add it
9797
// if the script is in TypeScript, so let's do the same for a seamless experience.
98-
const isTS =
99-
descriptor.script && /^typescript$|tsx?$/.test(descriptor.script.lang)
98+
const lang =
99+
(descriptor.scriptSetup && descriptor.scriptSetup.lang) ||
100+
(descriptor.script && descriptor.script.lang)
101+
const isTS = /^typescript$|tsx?$/.test(lang)
100102

101103
const result = compileTemplate({
102104
id: filename,

0 commit comments

Comments
 (0)