我有一个使用
我已经按照上面链接中的步骤完全操作,并创建了一个基本测试,它基本上什么都不做,只是为了让我能够运行测试。
在运行
如果我将导入行更改为:
问题在于,我不能像这个虚拟示例一样仅使用
我肯定错过了其他东西,因为Javascript实现指南使用的是
create-react-app
创建的基本React
应用程序。我正在尝试使用Pact开始使用Javascript实现指南对我的API进行合同测试。我已经按照上面链接中的步骤完全操作,并创建了一个基本测试,它基本上什么都不做,只是为了让我能够运行测试。
import { Pact } from '@pact-foundation/pact';
it('works', () => {
expect(1).toEqual(1);
});
在运行
npm run pactTest
时,我收到了以下错误信息: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:
/path/to/file.test.pact.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { Pact } from '@pact-foundation/pact';
^
SyntaxError: Unexpected token {
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
如果我将导入行更改为:
const Pact = require('@pact-foundation/pact');
,那么它就可以运行了。问题在于,我不能像这个虚拟示例一样仅使用
require
,因为我在整个React
项目中都使用import
。我肯定错过了其他东西,因为Javascript实现指南使用的是
import { Pact } from '@pact-foundation/pact';
。