{"action":"created","issue":{"url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/777","labels_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/777/labels{/name}","comments_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/777/comments","events_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/777/events","html_url":"https://github.com/cjohansen/Sinon.JS/issues/777","id":92429186,"number":777,"title":"Proposal: Stub non-enumerable properties when only object is given","user":{"login":"traviskaufman","id":1185269,"avatar_url":"https://avatars.githubusercontent.com/u/1185269?v=3","gravatar_id":"","url":"https://api.github.com/users/traviskaufman","html_url":"https://github.com/traviskaufman","followers_url":"https://api.github.com/users/traviskaufman/followers","following_url":"https://api.github.com/users/traviskaufman/following{/other_user}","gists_url":"https://api.github.com/users/traviskaufman/gists{/gist_id}","starred_url":"https://api.github.com/users/traviskaufman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/traviskaufman/subscriptions","organizations_url":"https://api.github.com/users/traviskaufman/orgs","repos_url":"https://api.github.com/users/traviskaufman/repos","events_url":"https://api.github.com/users/traviskaufman/events{/privacy}","received_events_url":"https://api.github.com/users/traviskaufman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-07-01T16:35:01Z","updated_at":"2015-07-27T17:26:04Z","closed_at":null,"body":"Using sinon v1.15.3, the following code snippet does not work\r\n\r\n```javascript\r\nclass Foo {\r\n  doSomething() {\r\n    var thing = 0;\r\n    // do stuff with thing...\r\n    return thing;\r\n  }\r\n}\r\n\r\nconst fooStub = sinon.createStubInstance(Foo);\r\nfooStub.doSomething.returns(1);\r\n```\r\n\r\nThe last line throws a `TypeError`, saying that `doSomething` does not have a `returns` method. This is due to the fact that function defined in class expressions are attached as [non-enumerable properties](http://www.ecma-international.org/ecma-262/6.0/#sec-runtime-semantics-classdefinitionevaluation) (see step 21.a), but [within sinon.stub](https://github.com/cjohansen/Sinon.JS/blob/master/lib/sinon/stub.js#L51-L55) a `for..in` loop is used, meaning any non-enumerable property is excluded. \r\n\r\nI think it would help with the future-forwardness of sinon to use something like `Object.getOwnPropertyNames` instead of `for..in` when using stub with only an object, because it would allow `createStubInstance` to interop seamlessly with class definitions, and I would be happy to submit a PR for this. I was just wondering if there are any arguments against stubbing non-enumerable properties and if so what would be a good solution to allow stubbing them in certain cases?"},"comment":{"url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/comments/125279612","html_url":"https://github.com/cjohansen/Sinon.JS/issues/777#issuecomment-125279612","issue_url":"https://api.github.com/repos/cjohansen/Sinon.JS/issues/777","id":125279612,"user":{"login":"cjohansen","id":32871,"avatar_url":"https://avatars.githubusercontent.com/u/32871?v=3","gravatar_id":"","url":"https://api.github.com/users/cjohansen","html_url":"https://github.com/cjohansen","followers_url":"https://api.github.com/users/cjohansen/followers","following_url":"https://api.github.com/users/cjohansen/following{/other_user}","gists_url":"https://api.github.com/users/cjohansen/gists{/gist_id}","starred_url":"https://api.github.com/users/cjohansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjohansen/subscriptions","organizations_url":"https://api.github.com/users/cjohansen/orgs","repos_url":"https://api.github.com/users/cjohansen/repos","events_url":"https://api.github.com/users/cjohansen/events{/privacy}","received_events_url":"https://api.github.com/users/cjohansen/received_events","type":"User","site_admin":false},"created_at":"2015-07-27T17:26:04Z","updated_at":"2015-07-27T17:26:04Z","body":"Sounds like a good idea. "}}