简体   繁体   English

为什么async()在Jest测试中转换为异步函数()?

[英]Why async () transform to async function () in Jest tests?

My jest test case is similar to: 我的开玩笑测试用例类似于:

test('should update state.focus', async () => {
  let component = getComponent()
  component.setState({focus: true})
  expect(component.state().focus).toEqual(true)
  component.instance().handleBlur()

  await expect(component.state().focus).toEqual(false)
})

This works fine in local dev environment. 这在本地开发环境中工作正常。 However it fails on bamboo giving the following error: 但是它在竹子上失败了,给出了以下错误:

test('should update state.focus', async function () {
                                  ^^^^^
SyntaxError: missing ) after argument list

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
  at handle (node_modules/worker-farm/lib/child/index.js:41:8)
  at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:47:3)
  at emitTwo (events.js:106:13)

I am using jest - 20.0.3 and babel-jest 20.0.3 我正在使用jest - 20.0.3和babel-jest 20.0.3

I had exactly the same problem. 我有完全相同的问题。 I could solve it by installing the babel-preset-es2017 package and then use it in the .babelrc 我可以通过安装babel-preset-es2017软件包解决它,然后在.babelrc使用它

{
  "presets": ["es2017"]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM