When runnig JEST unit tests in a project with Angular 5 and ngx-bootstrap Modal, the following error occurs:
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { BsModalRef } from './bs-modal-ref.service';
^^^^^^
SyntaxError: Unexpected token export
ngx-bootstrap: ^2.0.3
Angular: ^5.2.8
Bootstrap: ^4.0.0
jest: ^22.4.0
jest-preset-angular: ^5.2.1
Angular CLI: 1.7.3
Node: 8.9.4
OS: win32 x64
Angular: 5.2.8
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cli: 1.7.3
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0
You'll have to do the 3 things mentioned here.
https://github.com/thymikee/jest-preset-angular#unexpected-token-importexportother
Something like
"jest": {
"transform": {
"^.+\.(ts|html)$": "
"^.+\.js$": "babel-jest"
},
"transformIgnorePatterns": [
"node_modules/(?!@ngrx|ngx-bootstrap|@progress)"
],
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "
},
and
"allowJs": true
in tsconfig.json
Most helpful comment
You'll have to do the 3 things mentioned here.
https://github.com/thymikee/jest-preset-angular#unexpected-token-importexportother
Something like
"jest": {/node_modules/jest-preset-angular/preprocessor.js",/src/setupJest.ts"
"transform": {
"^.+\.(ts|html)$": "
"^.+\.js$": "babel-jest"
},
"transformIgnorePatterns": [
"node_modules/(?!@ngrx|ngx-bootstrap|@progress)"
],
"preset": "jest-preset-angular",
"setupTestFrameworkScriptFile": "
},
and
"allowJs": true
in tsconfig.json