首页 > 解决方案 > 我如何模拟我的日期,以便它也可以在部署服务器上工作

问题描述

我正在开玩笑并做出反应。

我有以下测试:

import sut from '../../utils/timeFormater';

describe('timeFormater utils ', () => {
    test('hours should be 09 if the getHours method return number less then 10', () => {
        const date = new Date('Mon Feb 08 2021 09:18:11 GMT+0100 (Central European Standard Time');
        const result = sut(date);
        expect(result.split(':')[0]).toBe('09');
    });
});

在我在服务器上部署之后-时间比我早一个小时,所以当我期望时-expect(result.split(':')[0]).toBe('09');

它在我的本地机器上工作

但它在部署的服务器上不起作用 - 那里的测试失败了,因为那里

它收到 08 而不是 09

const date = new Date('Mon Feb 08 2021 09:18:11 GMT+0100 (Central European Standard Time');

我该如何解决这个问题?

标签: reactjsjestjs

解决方案


推荐阅读