简体   繁体   English

可选链操作符开玩笑测试

[英]optional chaining operator jest testing

Newer to jest testing and reaching out to the community for direction.较新的玩笑测试并与社区联系以寻求指导。 I need to write a jest test around the following block of code.我需要围绕以下代码块编写一个笑话测试。 The environment leverages jest, enzyme and chai.环境利用了笑话、酶和柴。 I have searched high and low for examples of optional chaining operator tests.我在高低搜索了可选链运算符测试的示例。 Any examples or links anyone can provide to point me in the right direction.任何人都可以提供的任何示例或链接为我指明正确的方向。

<TableCell
   key={i}
   size={columnResizing?.columnWidths[column.id] || column.size}
/>

To enable optional-chaining, install it, like this:要启用可选链接,请安装它,如下所示:

yarn add @babel/plugin-proposal-optional-chaining --dev

After installing it, you need to ensure it's registered within your babel plugins section, like so:安装后,您需要确保它已在您的 babel 插件部分中注册,如下所示:

{
  "plugins": ["@babel/plugin-proposal-optional-chaining"]
}

In case someone has a problem with optional chaining in jest + testing-library/react stack.如果有人在 jest + testing-library/react 堆栈中遇到可选链接问题。

Test failed because of "Support for the experimental syntax 'optionalChaining' isn't currently enabled" can be resolved by adding测试失败,因为“当前未启用对实验性语法 'optionalChaining' 的支持”可以通过添加解决

yarn add @babel/plugin-syntax-optional-chaining @babel/plugin-syntax-optional-chaining --dev

Add plugins inside .babelrc to enable transformation:在 .babelrc 中添加插件以启用转换:

  "plugins": [
    "@babel/plugin-syntax-optional-chaining",
    "@babel/plugin-proposal-optional-chaining"
   ]

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

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