Comments (7)
Potentially a duplicate of #493
from vue-jest.
@mikemklee try this:
globals: {
'vue-jest': {
compilerOptions: {
whitespace: 'preserve',
},
},
},
Works for me 🙂
from vue-jest.
@rogatty
I tried both:
globals: {
'@vue/vue3-jest': ...
and
globals: {
'vue-jest': ...
but neither seem to work for me sadly.
Do you mind sharing what versions you are using for jest
, vue-jest
, and @vue/test-utils
?
from vue-jest.
Upon further debugging, I noticed that the @vue/vue3-jest/lib/process.js::processScriptSetup()
is early exiting, causing the compilerOptions
to not get respected.
function processScriptSetup(descriptor, filePath, config) {
if (!descriptor.scriptSetup) { // <--- this will cause this method to early exit
return null
}
const vueJestConfig = getVueJestConfig(config)
const content = compileScript(descriptor, {
id: filePath,
refTransform: true,
...vueJestConfig.compilerOptions
})
const contentMap = mapLines(descriptor.scriptSetup.map, content.map)
const transformer = resolveTransformer(
descriptor.scriptSetup.lang,
vueJestConfig
)
const result = transformer.process(content.content, filePath, config)
result.map = mapLines(contentMap, result.map)
return result
}
I think by descriptor.scriptSetup
, it's trying to look for the
<script setup></script>
which is a new addition in vue 3.
For vue 2 components, descriptor.scriptSetup
will always be null
.
from vue-jest.
@mikemklee versions I'm using:
jest: 27.3.1
@vue/vue3-jest: 27.0.0
@vue/test-utils: 2.3.2
I don't use <script setup></script>
yet, I'm in the middle of migration to Vue 3. I use @vue/compat
in the app but not in the tests.
If you use .vue
files with <template>
then it should go through processTemplate
, I think:
vue-jest/packages/vue3-jest/lib/process.js
Line 115 in 89586a0
from vue-jest.
@rogatty
interesting, could you elaborate on what you said about using @vue/compat
in the app, but not in the tests?
is it possible to have the app running with the compat build, while also keeping the tests passing as-is?
context:
me and my team are also in the middle of our migration to Vue 3, and our tests are mostly failing after we:
- installed the compat build
- bumped
vue-test-utils
to v2
and we would like to figure out the best path forward that would minimize the amount of friction/changes required
from vue-jest.
@mikemklee there is https://www.npmjs.com/package/vue-test-utils-compat but it doesn't support the latest vue-test-utils
. It uses monkey patching and is very brittle.
There were some other issues I don't remember, and we've decided it's better to just migrate most of the tests, skip a few of problematic ones for now, and upgrade the app logic where necessary.
from vue-jest.
Related Issues (20)
- install errors
- Unable to mock $style object on a Vue 3 Options API based component using CSS Modules
- Issue with script and script setup in the same vue file HOT 5
- Upgrade TS target to ES6 HOT 3
- Instructions for setting up `vue-test` when migrating from Vue 2 to Vue 3? HOT 1
- New test fail with mistake ENOENT: no such file or directory, open HOT 1
- Using v8 as the coverageProvider, used files without tests are being reported with 100% coverage HOT 2
- Test fails to run when using CSS v-bind and parent directory starts with "x"
- DOCS: vue-jest 4.x doesn't support jest 25.x
- Cannot find module '@babel/preset-env'
- v-bind(css) + number prefix folder path + windows : make a syntax error HOT 1
- Incompatibility with Prettier v3 HOT 4
- Injecting SFC styles into the DOM using JSDom test environment HOT 1
- @use rules must be written before any other rules.
- Newest version on npmjs.com is 5.x alphs, but on GitHub it's up to 29.x
- Single uncovered line flagged by Vue `template` HOT 2
- 组件测试的时候,vuewrapper里面拿到的vm是空,使用的script setup写法,optionsApi写法是ok的?
- Bug: Props detection broken with jest since 2.4.2 (works in 2.4.1) HOT 7
- Tests fail due to "Cannot destructure property 'config' of 'undefined' as it is undefined."
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-jest.