samedi 21 novembre 2015

Mock object/function using QUnit and Sinon

Say I had this Person object (constructor function) with an age attribute which calls another function called calculateAge() - how would I go about mocking both the Person object and the calculateAge() methods using QUnit and Sinon.js?

function Person() {
    this.age = calculateAge();

    Person.prototype.calculateAge = function(birthYear) {
         var currYear = 2015;

         return currYear - birthYear;
    }
}

Any help would be much appreciated, thanks in advance!

Aucun commentaire:

Enregistrer un commentaire