{"action":"created","issue":{"url":"https://api.github.com/repos/sinonjs/sinon/issues/1687","repository_url":"https://api.github.com/repos/sinonjs/sinon","labels_url":"https://api.github.com/repos/sinonjs/sinon/issues/1687/labels{/name}","comments_url":"https://api.github.com/repos/sinonjs/sinon/issues/1687/comments","events_url":"https://api.github.com/repos/sinonjs/sinon/issues/1687/events","html_url":"https://github.com/sinonjs/sinon/issues/1687","id":296304193,"number":1687,"title":"Verifying a mock and an expectation may lead to different results","user":{"login":"tendlich","id":5444919,"avatar_url":"https://avatars2.githubusercontent.com/u/5444919?v=4","gravatar_id":"","url":"https://api.github.com/users/tendlich","html_url":"https://github.com/tendlich","followers_url":"https://api.github.com/users/tendlich/followers","following_url":"https://api.github.com/users/tendlich/following{/other_user}","gists_url":"https://api.github.com/users/tendlich/gists{/gist_id}","starred_url":"https://api.github.com/users/tendlich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tendlich/subscriptions","organizations_url":"https://api.github.com/users/tendlich/orgs","repos_url":"https://api.github.com/users/tendlich/repos","events_url":"https://api.github.com/users/tendlich/events{/privacy}","received_events_url":"https://api.github.com/users/tendlich/received_events","type":"User","site_admin":false},"labels":[{"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":0,"created_at":"2018-02-12T09:07:24Z","updated_at":"2018-03-22T19:50:25Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nnot sure if this is the expected behavior. Related issue https://github.com/sinonjs/sinon/issues/1166\r\n\r\n- sinon 4.2.2\r\n- node 6.12.2\r\n\r\n**What did you expect to happen?**\r\nA mock expectation error is thrown inside the code under test. Even if the exception is caught and silenced, I would expect that when calling mockExpectation.verify() the exception would be thrown again and make the test fail.\r\n\r\n**What actually happens**\r\nThe mockExpectation.verify() call passes.\r\n\r\n**How to reproduce**\r\n\r\n ```\r\n   const obj = {\r\n        fn: () => {\r\n        }\r\n    }\r\n\r\n    it('Silent error discarded when verifying expecation', () => {\r\n        const fnMockExpectation = sinon.mock(obj).expects(\"fn\").once();\r\n\r\n        obj.fn();\r\n        try {\r\n            obj.fn();\r\n        } catch (e) {}\r\n\r\n        fnMockExpectation.verify(); // does not throw an error\r\n    });\r\n```"},"comment":{"url":"https://api.github.com/repos/sinonjs/sinon/issues/comments/375435552","html_url":"https://github.com/sinonjs/sinon/issues/1687#issuecomment-375435552","issue_url":"https://api.github.com/repos/sinonjs/sinon/issues/1687","id":375435552,"user":{"login":"m90","id":1662740,"avatar_url":"https://avatars3.githubusercontent.com/u/1662740?v=4","gravatar_id":"","url":"https://api.github.com/users/m90","html_url":"https://github.com/m90","followers_url":"https://api.github.com/users/m90/followers","following_url":"https://api.github.com/users/m90/following{/other_user}","gists_url":"https://api.github.com/users/m90/gists{/gist_id}","starred_url":"https://api.github.com/users/m90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m90/subscriptions","organizations_url":"https://api.github.com/users/m90/orgs","repos_url":"https://api.github.com/users/m90/repos","events_url":"https://api.github.com/users/m90/events{/privacy}","received_events_url":"https://api.github.com/users/m90/received_events","type":"User","site_admin":false},"created_at":"2018-03-22T19:50:25Z","updated_at":"2018-03-22T19:50:25Z","author_association":"NONE","body":"I got bitten by the same, and it looks to me as if it's more of a docs issue.\r\n\r\nThe following test will pass:\r\n\r\n```js\r\nit(\"throws if called too often\", function () {\r\n    var mock = this.mock;\r\n    var object = this.object;\r\n\r\n    this.mock.expects(\"method\").once();\r\n\r\n    object.method();\r\n    try {\r\n        object.method();\r\n    } catch (err) {/* discard on purpose */}\r\n\r\n    assert.exception(function () {\r\n        mock.verify();\r\n    }, \"ExpectationError\");\r\n});\r\n```\r\n\r\nwhereas the following will fail:\r\n\r\n```js\r\nit(\"throws if called too often\", function () {\r\n    var mock = this.mock.expects(\"method\").once();\r\n    var object = this.object;\r\n\r\n    object.method();\r\n    try {\r\n        object.method();\r\n    } catch (err) {/* discard on purpose */}\r\n\r\n    assert.exception(function () {\r\n        mock.verify();\r\n    }, \"ExpectationError\");\r\n});\r\n```\r\n\r\nIt kind of makes sense when looking at what the code does, but it's not very intuitive as both return values expose a `verify()` method. Is there a section in the docs about this?\r\n\r\nPossibly related are #739 and #1748 "}}
{"actor":{"display_login":"m90"}}