Vuetify Version: 1.5.16
Vue Version: 2.6.10
Browsers: Chrome 76.0.3809.100
OS: Mac OS 10.15.0
yarn install
yarn test:unit
to serve
vue serve src/dev.vue
Working smoothly with single file component structure from vue
Syntax Error
https://github.com/sametsafak/sfc-jest
I am trying to create a single file component and write unit tests with jest. Project works with vue's instant prototyping method.
Normally project and tests are working smoothly but not with vuetify.
When I try to import vuetify components, jest gives me SyntaxError: Unexpected identifier error on importing vuetify components line (src/components/FcTable.vue:41:1). I checked my environment to make sure if it's an es6 import issue but it's not. I can import and use another script files.
There is an ongoing issue with https://github.com/vuejs/vue-cli/issues/1584 . Not sure if something pops out at @KaelWD .
I have this in a project at work:
transform: { '^.*\\.js$': 'babel-jest' },
transformIgnorePatterns: ['node_modules/(?!vue-router|@babel|vuetify)']
May also need some babel config changes, idk.
Adding that transformIgnorePatterns
property to my Jest config did the trick
Thank you, @KaelWD 馃檹
馃毃 DISREGARD: THIS DOESN'T WORK LIKE I THOUGHT 馃毃
@KaelWD solution works for me. Here is another alternative that I found to be faster to run:
js// jest.config.js
module.exports = {
// ... other config ...
moduleNameMapper: {
// ... other mapped names ...
'vuetify/lib': '<rootDir>/node_modules/vuetify/es5',
}
}
The reason this works is because Vuetify ships with a pre-compiled ES5 version, so just mapping to that one prevents you from having to use Babel or any other sort of pre-processor.
@morphatic note that isn't 100% equivalent as vuetify/es5
doesn't export components, so anything other than the default import from vuetify/lib
will fail.
Yeah, sorry. I've been banging my head against Jest and TS all day. I was sure I understood it at the time... 馃槗
It will work in most cases if you aren't manually importing anything else, just something to be aware of if you start getting problems. babel-jest
should be just as fast after the first run as it caches the compilation result.
Adding that transformIgnorePatterns property to my Jest config did the trick
That worked for me too. Thank you @KaelWD ! 馃帀
My jest.config.js
:
module.exports = {
preset: '@vue/cli-plugin-unit-jest/presets/typescript-and-babel',
setupFilesAfterEnv: ['<rootDir>tests/setup.ts'],
transformIgnorePatterns: ['node_modules/(?!vue-router|@babel|vuetify)']
}
Most helpful comment
I have this in a project at work:
May also need some babel config changes, idk.