生成的快照的字段值有所不同:空字符串与未定义

时间:2019-01-07 18:35:51

标签: reactjs unit-testing jestjs snapshot

问题摘要

我对某些React组件的Jest快照测试在本地通过得很好,但是在CI的构建代理机器上失败了。我确保我的测试针对相同的代码(已确认使用git哈希)和配置运行。

由于某些原因,本地创建的快照在某些位置获得""值,而CI主机上的相同快照获得undefined值。

过去,当我的计算机上的节点版本为8.x.x且构建代理使用6.x.x时,我遇到了相同的问题。但是现在情况并非如此(请参见下面的版本)。

我很困惑:我在哪里开始调查?

工具版本

         Dev machine     CI build agent host
node         v8.14.0                 v8.11.1
yarn          1.12.3                   1.6.0
npm            6.4.1                   5.6.0

测试失败日志(摘录)

2019-01-06T23:41:27.2918318Z   ● SelectUserDropdownComponent › should render SelectUserDropdownComponent
2019-01-06T23:41:27.2919101Z 
2019-01-06T23:41:27.2919451Z     expect(value).toMatchSnapshot()
2019-01-06T23:41:27.2920151Z 
2019-01-06T23:41:27.2920606Z     Received value does not match stored snapshot "SelectUserDropdownComponent should render SelectUserDropdownComponent 1".
2019-01-06T23:41:27.2920869Z 
2019-01-06T23:41:27.2921115Z     - Snapshot
2019-01-06T23:41:27.2921594Z     + Received
2019-01-06T23:41:27.2921763Z 
2019-01-06T23:41:27.2923351Z     @@ -122,11 +122,11 @@
2019-01-06T23:41:27.2923596Z           },
2019-01-06T23:41:27.2923949Z           "ref": null,
2019-01-06T23:41:27.2924249Z           "rendered": Array [
2019-01-06T23:41:27.2924482Z             Object {
2019-01-06T23:41:27.2924711Z               "instance": null,
2019-01-06T23:41:27.2925046Z     -         "key": "",
2019-01-06T23:41:27.2925294Z     +         "key": undefined,
2019-01-06T23:41:27.2925532Z               "nodeType": "host",
2019-01-06T23:41:27.2925778Z               "props": Object {
2019-01-06T23:41:27.2926121Z                 "children": "Unassign",
2019-01-06T23:41:27.2926369Z                 "value": "",
2019-01-06T23:41:27.2926599Z               },
2019-01-06T23:41:27.2926920Z     @@ -227,11 +227,11 @@
2019-01-06T23:41:27.2927152Z             },
2019-01-06T23:41:27.2927376Z             "ref": null,
2019-01-06T23:41:27.2927618Z             "rendered": Array [
2019-01-06T23:41:27.2927958Z               Object {
2019-01-06T23:41:27.2928224Z                 "instance": null,
2019-01-06T23:41:27.2928466Z     -           "key": "",
2019-01-06T23:41:27.2928709Z     +           "key": undefined,
2019-01-06T23:41:27.2929077Z                 "nodeType": "host",
2019-01-06T23:41:27.2929405Z                 "props": Object {
2019-01-06T23:41:27.2929685Z                   "children": "Unassign",
2019-01-06T23:41:27.2930053Z                   "value": "",
2019-01-06T23:41:27.2930303Z                 },
2019-01-06T23:41:27.2930455Z 
2019-01-06T23:41:27.2930668Z       29 | 
2019-01-06T23:41:27.2931079Z       30 |     it('should render SelectUserDropdownComponent', () => {
2019-01-06T23:41:27.2931403Z     > 31 |         expect(getWrapper()).toMatchSnapshot();
2019-01-06T23:41:27.2931693Z          |                              ^
2019-01-06T23:41:27.2931950Z       32 |     });
2019-01-06T23:41:27.2932278Z       33 | 
2019-01-06T23:41:27.2932569Z       34 |     it('should call onChange function on input value change', () => {
2019-01-06T23:41:27.2932782Z 
2019-01-06T23:41:27.2933081Z       at Object.<anonymous> (wmclient/js/Components/App/__tests__/SelectUserDropdownTests.tsx:31:30)
2019-01-06T23:41:27.2933431Z 
2019-01-06T23:41:27.2933785Z  › 1 snapshot failed.

0 个答案:

没有答案