处理快照测试中的时区差异的最佳实践?

时间:2017-09-08 14:32:44

标签: jestjs enzyme

我们使用airbnb的酶库与Jest进行快照测试。

当我的快照测试由不同时区的开发人员运行时,测试失败,因为其他开发人员的组件将呈现对象的创建日期,而不是我的时区。该怎么办?

const myCloudObject: CloudObject = {
    uuid: '82e04b65-8b40-449e-8c0d-b7ba87bf814d',
    name: 'myFile',
    path: 'pgblu/myFile',
    permissions: {Owner: ['Read', 'Write', 'Execute']},
    owner: 'pgblu',
    creationDate: new Date('2017-07-14 10:10:01.0'),
    modificationDate: new Date('Mon Jul 24 08:05:47 CDT 2017'),
    size: '200',
    type: 'application'
}

测试:

import {shallow} from 'enzyme';
...
describe('Infobar', () => {
...
    it('renders an Infobar component with one selection', () => {
        const wrapper: ShallowWrapper = shallow(<Infobar selectedItems={[myCloudObject]} />);
        const result: JSON = toJson(wrapper);
        expect(result).toMatchSnapshot();
    });
...});

我的远程同事的错误报告:

● Infobar › renders an Infobar component with one selection

expect(value).toMatchSnapshot()

Received value does not match stored snapshot 1.

- Snapshot
+ Received
...
@@ -147,22 +147,22 @@
         className="leftColumn">
         Added
       </span>
       <span
         className="mainColumn">
-        Fri, Jul 14, 2017, 10:10:01 AM CDT
+        Fri, Jul 14, 2017, 10:10:01 AM GMT+2
       </span>
     </div>
     <div
       className="row">
       <span
         className="leftColumn">
         Modified
       </span>
       <span
         className="mainColumn">
-        Mon, Jul 24, 2017, 8:05:47 AM CDT
+        Mon, Jul 24, 2017, 3:05:47 PM GMT+2
       </span>
     </div>
...

0 个答案:

没有答案