I have this excpetion
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it\'s not p
I added this setting to my config, but no joy. Still getting the same error as Sergey Aslanvov.
"transformIgnorePatterns": [
"/node_modules/(?!@vuetify)"
],
also tried
"transformIgnorePatterns": [
"\\node_modules\\@vuetify",
],
Below is a sample of my component that extends VDataTable
import {
Vue,
Mixins,
Component,
} from 'vue-property-decorator';
import { VDataTable } from 'vuetify/lib';
@Component
export class BPagedGrid extends Mixins(Vue, VDataTable) { }
I had a similar error while working on a project with jest, webpack, and vanilla js, so that error is thrown when jest encounters this line of code import '../css/styles.css'; in any /*?.js$/ file. I solved it by moving the jest configurations from the package.json file into a jest.config.js file with the following minimal configuration;
// jest.config.js
module.exports =
"moduleNameMapper": {
"\\.(css|less|scss)$": "identity-obj-proxy"
}
}
Then in babel.config.js
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};
Actually, it seems like typescript is not going well with JEST test cases, so what i feel like either JEST need to ignore those files or those packages need to be transpiled to js code which JEST can understand,
you can try this
"transformIgnorePatterns": [ "node_modules/(?!(@microsoft/sp-core-library))" ],
and in tsconfig.json
"allowJs": true,
for more details please check this post
https://github.com/SharePoint/sp-dev-docs/issues/2325#issuecomment-446416878
The transformIgnorePatterns
means if the test path matches any of the patterns, it will not be transformed.
Note: DO NOT SPLIT MULTI-LINES.
The jest will ignore all node_modules
via default.
So you must write like this:
"transformIgnorePatterns": [
// all exceptions must be first line
"/node_modules/(?!@microsoft/sp-core-library|sp-dialog|other_libs_need_transform)"
],