代码之家  ›  专栏  ›  技术社区  ›  dan-klasson

没有实体无法转换节点

  •  3
  • dan-klasson  · 技术社区  · 6 年前

    我想逃跑 the example 在里面 react-testing-library 测试反应钩。但在这方面似乎失败了:

    testHook(() => ({count, increment} = useCounter({ initialCount: 2 })))
    

    好像和巴贝尔有关。尝试了谷歌搜索,但找不到任何人似乎有同样的问题。我用安装了webpack create-react-app

    这是StackTrace:

     ● Test suite failed to run
    
      Can't convert node without a body
    
      at NodePath.ensureBlock (node_modules/@babel/traverse/lib/path/conversion.js:64:11)
      at Scope.push (node_modules/@babel/traverse/lib/scope/index.js:727:12)
      at Object.toSequenceExpression (node_modules/@babel/types/lib/converters/toSequenceExpression.js:19:11)
      at NodePath.replaceExpressionWithStatements (node_modules/@babel/traverse/lib/path/replacement.js:203:36)
      at NodePath.insertAfter (node_modules/@babel/traverse/lib/path/modification.js:128:17)
      at NodePath.replaceWithMultiple (node_modules/@babel/traverse/lib/path/replacement.js:85:22)
      at PluginPass.AssignmentExpression (node_modules/babel-preset-react-app/node_modules/@babel/plugin-transform-destructuring/lib/index.js:433:14)
      at newFn (node_modules/@babel/traverse/lib/visitors.js:193:21)
      at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:53:20)
      at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:40:17)
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   dan-klasson    6 年前

    我不知道如何解决巴别塔问题,但如果你写:

    testHook(() => { return ({count, increment} = useCounter({ initialCount: 2 }))})
    

    而不是:

    testHook(() => ({count, increment} = useCounter({ initialCount: 2 })))
    

    它起作用了。可能他们正在使用一些高级ES6语法糖,而您当前的设置没有。希望有帮助!