javascript - How do I stub new Date() using sinon? -
i want verify various date fields updated don't want mess around predicting when new date()
called. how stub out date constructor?
import sinon = require('sinon'); import should = require('should'); describe('tests', () => { var sandbox; var = new date(); beforeeach(() => { sandbox = sinon.sandbox.create(); }); aftereach(() => { sandbox.restore(); }); var = new date(); it('sets create_date', done => { sandbox.stub(date).returns(now); // not work widget.create((err, widget) => { should.not.exist(err); should.exist(widget); widget.create_date.should.eql(now); done(); }); }); });
in case relevant, these tests running in node app , use typescript.
i suspect want usefaketimers
function:
var = new date(); var clock = sinon.usefaketimers(now.gettime()); //assertions clock.restore();
this plain js. working typescript/javascript example:
var = new date(); beforeeach(() => { sandbox = sinon.sandbox.create(); clock = sinon.usefaketimers(now.gettime()); }); aftereach(() => { sandbox.restore(); clock.restore(); });
Javascript - How Do I Stub New Date() Using Sinon? - >>>>> Download Now
ReplyDelete>>>>> Download Full
Javascript - How Do I Stub New Date() Using Sinon? - >>>>> Download LINK
>>>>> Download Now
Javascript - How Do I Stub New Date() Using Sinon? - >>>>> Download Full
>>>>> Download LINK 3j