lundi 8 janvier 2018

How to checking function called in Promise by sinon

I was using mocha + chai + sinon to test function, but in promise use called property, even if write a undefined function, called always true, What is it caused by ?and how to resolve? thx

describe("when click get verifycode", function () {
it('if get server response success, should start countdown', function (done) {
    // given
    sandbox.stub(model, 'getVerifyCode').resolves({});
    sandbox.spy(view, 'startCountDown');
    // when
    var result = instance.onClickVerify('123456');
    // then
    result.then(res => {
        // no matter what function, called always true
        // e.g. expect(AnUndefinedFunction.called).to.be.ok;
        expect(instance.view.startCountDown.called).to.be.ok;
        done();
    }).catch(err => {
        done();
    });

Aucun commentaire:

Enregistrer un commentaire