cleishm / jsmockito

Javascript mocking framework inspired by the awesome mockito
http://jsmockito.org
Other
106 stars 19 forks source link

Spied object properties are undefined #14

Closed scottleedavis closed 11 years ago

scottleedavis commented 11 years ago

I am looking to test that a spy'ed object's method, modifies that object's properties properly. When doing this, I find that any reference to the spy'ed object's properties return 'undefined'. Not sure if I am doing this correctly, if it is a bug, or if it is not possible for some reason... here is a sample of what I am trying to do. The asserts on the object property never pass as the property is always undefined...

I am using QUnit for my unit tests.

JsHamcrest.Integration.QUnit();
JsMockito.Integration.QUnit();

function tester(){
    this.vals = [];
}

tester.prototype.addVal = function(val){
    this.vals.push(val);
}

tester.prototype.getVal = function(id){
    return this.vals[id];
}

test("tester demo", function() {

    var test = spy(new tester());

    test.addVal('foo');

    assertThat(test.vals[0], not(equalTo(undefined)));
    assertThat(test.vals[0], test.getVal(0));

});