Skip to content

Commit 04a3233

Browse files
authored
feat: support TS in templates for @vue/vue3-jest (#394)
Vue 3.2.13 introduced the support of TS expressions in templates, with a new `isTs` option of the compiler. (See [the relevant commit](vuejs/core@0dc521b)) vue-loader and vite chose to enable this by default if the script uses TS: - [vue-loader](vuejs/vue-loader@7613534) - [vite](vitejs/vite@01fa2ab) This commit enables the same behavior in vue-jest: if the script is using TS, then the `isTs` option is passed to the compiler. TS developers won't have to worry about setting the options themselves, making it coherent with what vue-loader and vite do.
1 parent a59135a commit 04a3233

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

e2e/3.x/typescript/src/components/Basic.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<template>
22
<div class="hello">
3-
<h1 :class="headingClasses">{{ msg }}</h1>
3+
<!-- Vue 3.2.13 supports TS in templates -->
4+
<!-- hence the `!` after `msg` to check if vue-jest supports it as well -->
5+
<h1 :class="headingClasses">{{ msg! }}</h1>
46
</div>
57
</template>
68

packages/vue3-jest/lib/process.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ function processTemplate(descriptor, filename, config) {
9191
bindings = scriptSetupResult.bindings
9292
}
9393

94+
// Since Vue 3.2.13, it's possible to use TypeScript in templates,
95+
// but this needs the `isTS` option of the compiler.
96+
// We could let users set it themselves, but vue-loader and vite automatically add it
97+
// 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)
100+
94101
const result = compileTemplate({
95102
id: filename,
96103
source: template.content,
@@ -100,6 +107,7 @@ function processTemplate(descriptor, filename, config) {
100107
compilerOptions: {
101108
bindingMetadata: bindings,
102109
mode: 'module',
110+
isTS,
103111
...vueJestConfig.compilerOptions
104112
}
105113
})

0 commit comments

Comments
 (0)