[AC-3003] global `setTimeout()` short-circuits the target object
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2012-05-29T22:34:17.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | settimeout, testing |
Reporter | Kenneth Kan |
Assignee | Betty Tran |
Created | 2012-05-25T15:52:27.000+0000 |
Updated | 2016-03-08T07:48:01.000+0000 |
Description
setTimeout seems to break method replacements by spies. The
this
in object a
does not refer to the same c
as replaced by the spy. Tried this on SDK 1.7.0, 1.8.2, and 2.0.1 with Sinon.js and Jasmine testing frameworks.
{noformat}
a = {
b: function() {
Ti.API.debug("a.b() called");
this.c();
},
c: function() {
Ti.API.debug("a.c() called");
}
};
describe("some test suite", function(){
it("some test case", function(){
setTimeout(function(){ a.b(); }, 1000);
// or setTimeout(function(){ eval("a.b();"); }, 1000);
spyOn(a, "b");
spyOn(a, "c");
// or sinon.spy(a, "b");
// sinon.spy(a, "c");
// After 1 second...
// "[DEBUG] a.b() called" is printed to terminal
// "[DEBUG] a.c() called" is printed to terminal
expect(a.b.callCount).toEqual(0); // succeed
expect(a.b).toHaveBeenCalled(); // fail
expect(a.c.callCount).toEqual(0); // succeed
expect(a.c).toHaveBeenCalled(); // fail
});
});
{noformat}
My apology. This is actually valid behavior. Because I used jasmine-titanium the test suite output is on the simulator and I made incorrect assumption. After having attached timestamp to the output. The order is correct. Someone with the authority to close this ticket please do so. Thank you.
Ticket closed as this is valid behavior.
Closing as per Kenneth's comment.