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(); }); 

Comments

  1. Javascript - How Do I Stub New Date() Using Sinon? - >>>>> Download Now

    >>>>> 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

    ReplyDelete

Post a Comment

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -