简体   繁体   English

酶测试由于在React 16中掉毛而失败

[英]Enzyme tests fail due to linting in React 16

I'm in the process of upgrading a project to React 16. When I run yarn test many tests now fail due to linting/formatting errors eg 我正在将项目升级到React16。在运行yarn test许多测试现在由于掉毛/格式化错误而失败,例如

  + expected - actual

             disabled={false}
             name="ticketTime"
             placeholder="Setup instructions.."
             rows={10}
          -  value="Sample text"
          ->
          +  value="Sample text">


...

      -          "label": "one",
      +          "label": "one"
               }
      -      }
      -    >
...

    + expected - actual

           <div>
          -  <h1
          -    key="0"
          -  >
          +  <h1>

Does anyone have any ideas why this is happening and how I can fix the tests? 有谁知道为什么会发生这种情况以及如何修复测试?

Based on our conversation in the comments, it sounds like you are using Jest with Enzyme, and probably need to update your snapshots: 根据我们在评论中的对话,听起来您正在将Jest与Enzyme一起使用,并且可能需要更新快照:

jest --updateSnapshot

This will render your HTML per the current code, to reflect any changes, including linting changes, that may make the HTML different, and update the snapshot files. 这将按照当前代码呈现HTML,以反映可能会使HTML有所不同的任何更改(包括更改),并更新快照文件。

When your tests run, they inspect the snapshots, and if they aren't up to date, the tests will fail. 运行测试时,他们将检查快照,如果快照不是最新的,则测试将失败。

https://facebook.github.io/jest/docs/en/snapshot-testing.html https://facebook.github.io/jest/docs/en/snapshot-testing.html

您可以使用以下方法更新快照:

yarn test -- -u

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

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