Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions e2e/3.x/typescript/src/components/ScriptSetup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<button @click="increase">Count: {{ num }}</button>
<Basic />
<span>{{ msg! }}</span>
</template>

<script setup lang="ts">
import Basic from './Basic.vue'
import { ref } from 'vue'

const num = ref(5)
const greet = () => console.log('greet')
const increase = () => {
greet()
num.value++
}
const msg = 'hello world'
</script>
7 changes: 7 additions & 0 deletions e2e/3.x/typescript/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createApp, h } from 'vue'

import Basic from '@/components/Basic.vue'
import ScriptSetup from '@/components/ScriptSetup.vue'

function mount(Component: any) {
document.getElementsByTagName('html')[0].innerHTML = ''
Expand All @@ -21,3 +22,9 @@ test('processes .vue files', () => {
'Welcome to Your Vue.js App'
)
})

test('supports <script setup>', () => {
mount(ScriptSetup)
expect(document.body.outerHTML).toContain('Count: 5')
expect(document.body.outerHTML).toContain('Welcome to Your Vue.js App')
})
6 changes: 4 additions & 2 deletions packages/vue3-jest/lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ function processTemplate(descriptor, filename, config) {
// but this needs the `isTS` option of the compiler.
// We could let users set it themselves, but vue-loader and vite automatically add it
// if the script is in TypeScript, so let's do the same for a seamless experience.
const isTS =
descriptor.script && /^typescript$|tsx?$/.test(descriptor.script.lang)
const lang =
(descriptor.scriptSetup && descriptor.scriptSetup.lang) ||
(descriptor.script && descriptor.script.lang)
const isTS = /^typescript$|tsx?$/.test(lang)

const result = compileTemplate({
id: filename,
Expand Down