{ "id": "92423", "key": "AC-3003", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2012-05-29T22:34:17.000+0000", "created": "2012-05-25T15:52:27.000+0000", "labels": [ "settimeout", "testing" ], "versions": [], "issuelinks": [], "assignee": { "name": "btran", "key": "btran", "displayName": "Betty Tran", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2016-03-08T07:48:01.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "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.\r\n\r\n{noformat}\r\na = {\r\n b: function() {\r\n Ti.API.debug(\"a.b() called\");\r\n this.c();\r\n },\r\n c: function() {\r\n Ti.API.debug(\"a.c() called\");\r\n }\r\n};\r\n \r\ndescribe(\"some test suite\", function(){\r\n it(\"some test case\", function(){\r\n setTimeout(function(){ a.b(); }, 1000);\r\n // or setTimeout(function(){ eval(\"a.b();\"); }, 1000);\r\n \r\n spyOn(a, \"b\");\r\n spyOn(a, \"c\");\r\n // or sinon.spy(a, \"b\");\r\n // sinon.spy(a, \"c\");\r\n \r\n // After 1 second...\r\n // \"[DEBUG] a.b() called\" is printed to terminal\r\n // \"[DEBUG] a.c() called\" is printed to terminal\r\n expect(a.b.callCount).toEqual(0); // succeed\r\n expect(a.b).toHaveBeenCalled(); // fail\r\n expect(a.c.callCount).toEqual(0); // succeed\r\n expect(a.c).toHaveBeenCalled(); // fail\r\n });\r\n});\r\n{noformat}", "attachment": [], "flagged": false, "summary": "global `setTimeout()` short-circuits the target object", "creator": { "name": "kenhkan", "key": "kenhkan", "displayName": "Kenneth Kan", "active": true, "timeZone": "America/New_York" }, "subtasks": [], "reporter": { "name": "kenhkan", "key": "kenhkan", "displayName": "Kenneth Kan", "active": true, "timeZone": "America/New_York" }, "environment": "[INFO] Titanium SDK version: 2.0.1 (04/12/12 16:33 999c68a)\r\n[INFO] iPhone Device family: iphone\r\n[INFO] iPhone SDK version: 4.2\r\n[INFO] iPhone simulated device: iphone\r\n\r\nMac OS X Snow Leopard\r\nLibraries: Sinon.js, Jasmine", "comment": { "comments": [ { "id": "196426", "author": { "name": "kenhkan", "key": "kenhkan", "displayName": "Kenneth Kan", "active": true, "timeZone": "America/New_York" }, "body": "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.", "updateAuthor": { "name": "kenhkan", "key": "kenhkan", "displayName": "Kenneth Kan", "active": true, "timeZone": "America/New_York" }, "created": "2012-05-29T19:48:01.000+0000", "updated": "2012-05-29T19:48:01.000+0000" }, { "id": "196437", "author": { "name": "btran", "key": "btran", "displayName": "Betty Tran", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Ticket closed as this is valid behavior.", "updateAuthor": { "name": "btran", "key": "btran", "displayName": "Betty Tran", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-05-29T22:34:17.000+0000", "updated": "2012-05-29T22:34:17.000+0000" }, { "id": "285991", "author": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing as per Kenneth's comment.", "updateAuthor": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2013-12-27T20:09:28.000+0000", "updated": "2013-12-27T20:09:28.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }