【问题标题】:Why is Jest updating all snapshots in my project?为什么 Jest 更新我项目中的所有快照?
【发布时间】:2019-02-08 14:59:36
【问题描述】:

我写了一些测试,一切都很顺利。然后我需要更新我的快照。不幸的是,它是在运行更新快照之后。它似乎已经编辑了所有组件快照。即使对于组件,我也没有改变。当我查看差异时,我看到了这个:

 exports[`MyComponent should render correctly 1`] = `
 ShallowWrapper {
-  "length": 1,
   Symbol(enzyme.__root__): [Circular],
   Symbol(enzyme.__unrendered__): <FileManagement
     areYouSure="Are you sure?"
@@ -1250,8 +1249,20 @@ ShallowWrapper {
     "adapter": ReactSixteenAdapter {
       "options": Object {
         "enableComponentDidUpdateOnSetState": true,
+        "lifecycles": Object {
+          "componentDidUpdate": Object {
+            "onSetState": true,
+          },
+          "getDerivedStateFromProps": true,
+          "getSnapshotBeforeUpdate": true,
+          "setState": Object {
+            "skipsComponentDidUpdateOnNullish": true,
+          },
+        },
       },
     },
+    "attachTo": undefined,
+    "hydrateIn": undefined,
   },

任何帮助都会很棒,因为它破坏了我的 Jenkins 工作,而我似乎无法修复它。我不确定为什么它会将密钥添加到快照中?还有为什么它对所有人都这样做。

我正在使用 Node 版本 10.9 和 Jest 版本 22.4.3

【问题讨论】:

  • 我在使用 yarn 而不是 npm 运行测试时遇到了这个问题。

标签: reactjs unit-testing jasmine jestjs enzyme


【解决方案1】:

您需要酶转 json 插件以使您的快照更易于阅读。至于您未更改的组件的更新快照,肯定是其他人更改了它们,并且他们没有更新快照。每当您更改组件的呈现方式时,您都需要更新预期的快照。

【讨论】:

    猜你喜欢
    • 2012-03-15
    • 1970-01-01
    • 2021-08-23
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 2023-03-24
    • 2012-08-31
    相关资源
    最近更新 更多