解决方案
import {expect} from '@loopback/testlab';
import sinon from 'sinon';
describe('example test', () => {
let clock: sinon.SinonFakeTimers;
before(() => {
clock = sinon.useFakeTimers();
});
after(() => {
clock.restore();
});
it('should return the correct date', () => {
// set the clock to a specific time
clock.setSystemTime(new Date('2022-05-01T00:00:00Z'));
const currentDate = new Date();
expect(currentDate.getFullYear()).to.equal(2022);
expect(currentDate.getMonth()).to.equal(4);
expect(currentDate.getDate()).to.equal(1);
});
});
标签:冻结,clock,单元测试,equal,loopback4,sinon,expect,currentDate
From: https://www.cnblogs.com/leoych/p/17356224.html