{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/jest/issues/1626","repository_url":"https://api.github.com/repos/facebook/jest","labels_url":"https://api.github.com/repos/facebook/jest/issues/1626/labels{/name}","comments_url":"https://api.github.com/repos/facebook/jest/issues/1626/comments","events_url":"https://api.github.com/repos/facebook/jest/issues/1626/events","html_url":"https://github.com/facebook/jest/issues/1626","id":175349938,"number":1626,"title":"Clearing all mocks","user":{"login":"benweissmann","id":207390,"avatar_url":"https://avatars.githubusercontent.com/u/207390?v=3","gravatar_id":"","url":"https://api.github.com/users/benweissmann","html_url":"https://github.com/benweissmann","followers_url":"https://api.github.com/users/benweissmann/followers","following_url":"https://api.github.com/users/benweissmann/following{/other_user}","gists_url":"https://api.github.com/users/benweissmann/gists{/gist_id}","starred_url":"https://api.github.com/users/benweissmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benweissmann/subscriptions","organizations_url":"https://api.github.com/users/benweissmann/orgs","repos_url":"https://api.github.com/users/benweissmann/repos","events_url":"https://api.github.com/users/benweissmann/events{/privacy}","received_events_url":"https://api.github.com/users/benweissmann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-06T20:56:51Z","updated_at":"2016-09-14T04:35:44Z","closed_at":null,"body":"This was discussed before in #1285 but I think it's worth discussing again now that Jest 15 doesn't reset the module registry by default.\r\n\r\nI'd like to reset all mock calls in between tests. I propose adding a `jest.clearAllMocks()` function, which would proxy through to a `clearAllFunctionCalls()` method in `jest-mock`.\r\n\r\nFor the implementation inside `jest-mock`, I can think of two strategies:\r\n\r\n1. The simplest solution: maintain a global array of mock functions that gets added to when a new mock function is created by `mockComponent`. This is simple, but leaks references to all mock functions. \r\n\r\n2. Instead of storing `calls` directly on a mock function, store them on a WeakMap keyed by mock function. Reimplement `mockFn.calls` as a getter that reads from this WeakMap. To clear all function calls, we just replace the WeakMap with a new one. We could implement a setter for `calls` too, to preserve backwards compatibility (in case anyone is doing `mockFn.calls = []` to reset calls instead of using `mockClear` for some reason)\r\n\r\nI'm happy to implement this, but I figured I'd bring it up for discussion first to see if this is something you'd be willing to accept into Jest, and which of the above implementation strategies you'd prefer (I'm leaning towards 2)"},"comment":{"url":"https://api.github.com/repos/facebook/jest/issues/comments/246904244","html_url":"https://github.com/facebook/jest/issues/1626#issuecomment-246904244","issue_url":"https://api.github.com/repos/facebook/jest/issues/1626","id":246904244,"user":{"login":"cpojer","id":13352,"avatar_url":"https://avatars.githubusercontent.com/u/13352?v=3","gravatar_id":"","url":"https://api.github.com/users/cpojer","html_url":"https://github.com/cpojer","followers_url":"https://api.github.com/users/cpojer/followers","following_url":"https://api.github.com/users/cpojer/following{/other_user}","gists_url":"https://api.github.com/users/cpojer/gists{/gist_id}","starred_url":"https://api.github.com/users/cpojer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpojer/subscriptions","organizations_url":"https://api.github.com/users/cpojer/orgs","repos_url":"https://api.github.com/users/cpojer/repos","events_url":"https://api.github.com/users/cpojer/events{/privacy}","received_events_url":"https://api.github.com/users/cpojer/received_events","type":"User","site_admin":false},"created_at":"2016-09-14T04:35:44Z","updated_at":"2016-09-14T04:35:44Z","body":"This is a good idea, thanks for starting a PR."}}
{"actor":{"display_login":"cpojer"}}