{"action":"created","issue":{"url":"https://api.github.com/repos/flowtype/flow-typed/issues/291","repository_url":"https://api.github.com/repos/flowtype/flow-typed","labels_url":"https://api.github.com/repos/flowtype/flow-typed/issues/291/labels{/name}","comments_url":"https://api.github.com/repos/flowtype/flow-typed/issues/291/comments","events_url":"https://api.github.com/repos/flowtype/flow-typed/issues/291/events","html_url":"https://github.com/flowtype/flow-typed/issues/291","id":175202420,"number":291,"title":"typing jest mocks in tests","user":{"login":"JosePedroDiasSky","id":16103390,"avatar_url":"https://avatars.githubusercontent.com/u/16103390?v=3","gravatar_id":"","url":"https://api.github.com/users/JosePedroDiasSky","html_url":"https://github.com/JosePedroDiasSky","followers_url":"https://api.github.com/users/JosePedroDiasSky/followers","following_url":"https://api.github.com/users/JosePedroDiasSky/following{/other_user}","gists_url":"https://api.github.com/users/JosePedroDiasSky/gists{/gist_id}","starred_url":"https://api.github.com/users/JosePedroDiasSky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JosePedroDiasSky/subscriptions","organizations_url":"https://api.github.com/users/JosePedroDiasSky/orgs","repos_url":"https://api.github.com/users/JosePedroDiasSky/repos","events_url":"https://api.github.com/users/JosePedroDiasSky/events{/privacy}","received_events_url":"https://api.github.com/users/JosePedroDiasSky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-09-06T09:35:35Z","updated_at":"2016-10-18T23:49:03Z","closed_at":null,"body":"Extract of a jest test:\r\n\r\n```js\r\njest.mock('../../js/comm/ajax');\r\nimport ajax from '../../js/comm/ajax';\r\ndescribe('ConfigurationProvider', () => {\r\n  it('calling the fetchConfig() should return a promise', () => {\r\n    const expectedCfg = {x:'y'};\r\n    ajax.mockReturnValueOnce(\r\n      Promise.resolve({body:expectedCfg})\r\n    );\r\n    ...\r\n  });\r\n});\r\n```\r\n\r\nThe original ajax module exported a function so jest will intercept and return a JestMockFn instead. Flow says `property mockReturnValueOnce not found in statics of function`.\r\nHow do I let flow know of this? Should I cast the ajax symbol to the JestMockFn type? And how?\r\n\r\nThanks :)\r\n"},"comment":{"url":"https://api.github.com/repos/flowtype/flow-typed/issues/comments/254671789","html_url":"https://github.com/flowtype/flow-typed/issues/291#issuecomment-254671789","issue_url":"https://api.github.com/repos/flowtype/flow-typed/issues/291","id":254671789,"user":{"login":"aaronjensen","id":8588,"avatar_url":"https://avatars.githubusercontent.com/u/8588?v=3","gravatar_id":"","url":"https://api.github.com/users/aaronjensen","html_url":"https://github.com/aaronjensen","followers_url":"https://api.github.com/users/aaronjensen/followers","following_url":"https://api.github.com/users/aaronjensen/following{/other_user}","gists_url":"https://api.github.com/users/aaronjensen/gists{/gist_id}","starred_url":"https://api.github.com/users/aaronjensen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aaronjensen/subscriptions","organizations_url":"https://api.github.com/users/aaronjensen/orgs","repos_url":"https://api.github.com/users/aaronjensen/repos","events_url":"https://api.github.com/users/aaronjensen/events{/privacy}","received_events_url":"https://api.github.com/users/aaronjensen/received_events","type":"User","site_admin":false},"created_at":"2016-10-18T23:49:03Z","updated_at":"2016-10-18T23:49:03Z","body":"Perhaps adding a utility function would be handy:\r\n\r\n```js\r\nconst mock = (mockObject: any): MockObject => mockObject\r\n\r\nmock(ajax).mockReturnValueOnce(...)\r\n```\r\n\r\nYou could even potentially make that function polymorphic and strongly type things like `mockReturnValueOnce`."}}
{"actor":{"display_login":"aaronjensen"}}