samsonjs / strftime

strftime for JavaScript

Home Page:http://samhuri.net/projects/strftime

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Case with keeping the maximum past date

alexpts opened this issue · comments

I have problem with my unit test.

Example test for reproduce problem:

const chai = require('chai');
const sinon = require('sinon');
const strftime = require('strftime');

let { expect } = chai;

let sandbox = new sinon.createSandbox();

describe('strftime test', function () {
	afterEach(function () {
		sandbox.restore();
	});

	it('test one', () => {
		sandbox.useFakeTimers(new Date(2021,8,3));
		expect(strftime('%Y-%m-%d %H:%M:%S')).to.be.eq('2021-09-03 00:00:00'); // ok
	});

	it('test second, () => {
		sandbox.useFakeTimers(new Date(2021,8,1));
		expect(strftime('%Y-%m-%d %H:%M:%S')).to.be.eq('2021-09-01 00:00:00'); // fail 
	});
})

Problem relate with save state _cachedDateTimestamp/_cachedDate.

How can I reset the state for my case?