{"action":"created","issue":{"url":"https://api.github.com/repos/sinonjs/sinon/issues/1683","repository_url":"https://api.github.com/repos/sinonjs/sinon","labels_url":"https://api.github.com/repos/sinonjs/sinon/issues/1683/labels{/name}","comments_url":"https://api.github.com/repos/sinonjs/sinon/issues/1683/comments","events_url":"https://api.github.com/repos/sinonjs/sinon/issues/1683/events","html_url":"https://github.com/sinonjs/sinon/issues/1683","id":295799172,"number":1683,"title":"Spy's thisValue not pointing to instance when spying constructor","user":{"login":"PVince81","id":277525,"avatar_url":"https://avatars2.githubusercontent.com/u/277525?v=4","gravatar_id":"","url":"https://api.github.com/users/PVince81","html_url":"https://github.com/PVince81","followers_url":"https://api.github.com/users/PVince81/followers","following_url":"https://api.github.com/users/PVince81/following{/other_user}","gists_url":"https://api.github.com/users/PVince81/gists{/gist_id}","starred_url":"https://api.github.com/users/PVince81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PVince81/subscriptions","organizations_url":"https://api.github.com/users/PVince81/orgs","repos_url":"https://api.github.com/users/PVince81/repos","events_url":"https://api.github.com/users/PVince81/events{/privacy}","received_events_url":"https://api.github.com/users/PVince81/received_events","type":"User","site_admin":false},"labels":[{"id":249299926,"url":"https://api.github.com/repos/sinonjs/sinon/labels/Difficulty:%20Medium","name":"Difficulty: Medium","color":"bfdadc","default":false},{"id":249301120,"url":"https://api.github.com/repos/sinonjs/sinon/labels/Help%20wanted","name":"Help wanted","color":"0052cc","default":false},{"id":249318114,"url":"https://api.github.com/repos/sinonjs/sinon/labels/Needs%20investigation","name":"Needs investigation","color":"207de5","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-09T09:05:27Z","updated_at":"2018-02-11T20:04:57Z","closed_at":null,"author_association":"NONE","body":"This snippet works fine with Sinon 2.0.0 but fails with Sinon 4.2.2:\r\n```\r\n\tit('returns correct thisValue', function() {\r\n\t\twindow.SomeClass = function() {\r\n\t\t\tthis.counter = 0;\r\n\t\t\tthis.inc = function() {\r\n\t\t\t\tthis.counter++;\r\n\t\t\t};\r\n\t\t\tthis.getCounter = function() {\r\n\t\t\t\treturn this.counter;\r\n\t\t\t};\r\n\t\t};\r\n\r\n\t\tvar spy = sinon.spy(window, 'SomeClass');\r\n\t\tvar some = new window.SomeClass();\r\n\t\tsome.inc();\r\n\r\n\t\texpect(spy.thisValues[0].counter).toEqual(1);\r\n\t\texpect(spy.thisValues[0].getCounter()).toEqual(1);\r\n\t\tsome.inc();\r\n\t\texpect(spy.thisValues[0].counter).toEqual(2);\r\n\t\texpect(spy.thisValues[0].getCounter()).toEqual(2);\r\n\t});\r\n```\r\n\r\nIt looks like the `thisValues[0]` object is a proxy and does not refer to the actual instance of `some`.\r\n\r\nThis is the error with Sinon 4.2.2:\r\n```\r\nExpected undefined to equal 1\r\nTypeError: undefined is not a function (evaluating 'spy.thisValues[0].getCounter()')\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/sinonjs/sinon/issues/comments/364783065","html_url":"https://github.com/sinonjs/sinon/issues/1683#issuecomment-364783065","issue_url":"https://api.github.com/repos/sinonjs/sinon/issues/1683","id":364783065,"user":{"login":"PVince81","id":277525,"avatar_url":"https://avatars2.githubusercontent.com/u/277525?v=4","gravatar_id":"","url":"https://api.github.com/users/PVince81","html_url":"https://github.com/PVince81","followers_url":"https://api.github.com/users/PVince81/followers","following_url":"https://api.github.com/users/PVince81/following{/other_user}","gists_url":"https://api.github.com/users/PVince81/gists{/gist_id}","starred_url":"https://api.github.com/users/PVince81/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PVince81/subscriptions","organizations_url":"https://api.github.com/users/PVince81/orgs","repos_url":"https://api.github.com/users/PVince81/repos","events_url":"https://api.github.com/users/PVince81/events{/privacy}","received_events_url":"https://api.github.com/users/PVince81/received_events","type":"User","site_admin":false},"created_at":"2018-02-11T20:04:57Z","updated_at":"2018-02-11T20:04:57Z","author_association":"NONE","body":"Oh, I love bisecting! I'll take care of this.."}}
{"actor":{"display_login":"PVince81"}}