vendredi 2 octobre 2015

QUnit and SinonJS mocking

I would like to know how to mock (at least I think I need to do this) an instance of another object to pass test? Because when I launch test I get an error that getInstance is not a function. When inserting debugger in property getter which I am testing I see that mObjects contain two functions (the ones I am interested in actually), but one should be an instance so that it has all the methods and properties.

My getter which I am testing:

myModule = function(self) {
    var oProtected = self.oProtected || {};
    Object.defineProperty(Instance.prototype, "property", {
        get : function() {
            var FOO = oProtected.mObjects.AnotherObject.getInstance();
            return FOO.activeWindow.oPrivate.props().PROPERTY;
        }
    });
}

test:

assert.ok(this.Instance.property, "instance property available.");

Aucun commentaire:

Enregistrer un commentaire