Skip to content

feat: support TS in templates for @vue/vue3-jest #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2021
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
4 changes: 3 additions & 1 deletion e2e/3.x/typescript/src/components/Basic.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div class="hello">
<h1 :class="headingClasses">{{ msg }}</h1>
<!-- Vue 3.2.13 supports TS in templates -->
<!-- hence the `!` after `msg` to check if vue-jest supports it as well -->
<h1 :class="headingClasses">{{ msg! }}</h1>
</div>
</template>

Expand Down
8 changes: 8 additions & 0 deletions packages/vue3-jest/lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ function processTemplate(descriptor, filename, config) {
bindings = scriptSetupResult.bindings
}

// Since Vue 3.2.13, it's possible to use TypeScript in templates,
// 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 result = compileTemplate({
id: filename,
source: template.content,
Expand All @@ -100,6 +107,7 @@ function processTemplate(descriptor, filename, config) {
compilerOptions: {
bindingMetadata: bindings,
mode: 'module',
isTS,
...vueJestConfig.compilerOptions
}
})
Expand Down