在Mac上,我在安装jest并在angular / cli(v6)应用程序中工作时遇到问题。不管我用来开玩笑的方法(如下所示),我都会遇到错误:
console.log(self.options);
我尝试的方法包括:
Test suite failed to run
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 plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/owner/Code/testjest/src/setup-jest.ts:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import 'jest-preset-angular';
^^^^^^
SyntaxError: Unexpected token import
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
(https://github.com/briebug/jest-schematic)OTOH,当我克隆https://github.com/blove/ngrx-testing/tree/master时,回购文件运行得很好-我认为,这排除了我在全球安装的jest软件包的问题
以下SO答案无济于事:
答案 0 :(得分:1)
今天我发现了同样的错误消息,这就是我的解决方法。
//Hashing the ss with psSigningKey as the key
bufSignature = WL.HashString(HA_HMAC_SHA_256, ss, bufSigningKey)
//Converting the hash to hex
bufSignature = BufferToHexa(bufSignature, 1, 32)
//Converting the hex value to lower case and remove any whitespace
bufSignature = Replace(Lower(bufSignature), " ", "")
清除玩笑缓存jest --clearCache
ref:https://github.com/thymikee/jest-preset-angular/issues/194