Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vuejs/vue-jest
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 committed Oct 25, 2021
2 parents 1354116 + 800b6f4 commit 60ef3c7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
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

0 comments on commit 60ef3c7

Please sign in to comment.