-
Notifications
You must be signed in to change notification settings - Fork 9
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
[Resolved Question] vue-jest usage #8
Comments
You may need to add According to vue-jest Doc, the step may be:
// jest.config.js
module.exports = {
globals: {
'vue-jest': {
templateCompiler: {
compiler: require('vue-template-babel-compiler')
}
}
}
}
I haven't tested. If you run into any problem, just let me know. I would glad to help. |
Sadly this didn't work for me. Still getting the same error |
@monkemedia It will work for I just test by feat: add jest test example from vue-template-babel-compiler-nuxt-project ConfigNuxt.js && vue-jest DEMO project1. Package Version:
// package.json
"devDependencies": {
"@vue/test-utils": "^1.2.2",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.6.3",
"jest": "^26.6.3",
"vue-jest": "4.0.1",
"vue-template-babel-compiler": "^1.0.3"
} 2. jest.config.jsmodule.exports = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1',
'^~/(.*)$': '<rootDir>/$1',
'^vue$': 'vue/dist/vue.common.js',
},
moduleFileExtensions: ['js', 'vue', 'json'],
transform: {
'^.+\\.js$': 'babel-jest',
'.*\\.(vue)$': 'vue-jest',
},
globals: {
'vue-jest': {
templateCompiler: {
compiler: require('vue-template-babel-compiler')
}
}
}
} 3. test.spec.jsimport { mount } from '@vue/test-utils'
import Tutorial from '@/components/Tutorial.vue'
describe('jest test with vue-template-babel-compiler', () => {
test('should work for Optional Chaining', () => {
const wrapper = mount(Tutorial)
expect(wrapper.vm).toBeTruthy()
expect(wrapper.vm.$el.innerHTML).toMatch('Optional Chaining enabled: true')
})
}) Thank you for your feedback! |
You are a star. My vue-jest was below version 4. Thank you for you help :) |
I found that using functional components in jest will cause error as without the config Here is the full config
|
the above is not working for me on nuxt |
Optional chaining works greats in my Nuxt application, however, when I run my Jest unit tests, I get the following error message:
Jest encountered an unexpected token
In my jest.config.js file I have the following in my
transform
propertyCan I assume I will need to update the transform property?
The text was updated successfully, but these errors were encountered: