{"action":"created","issue":{"url":"https://api.github.com/repos/airbnb/enzyme/issues/1025","repository_url":"https://api.github.com/repos/airbnb/enzyme","labels_url":"https://api.github.com/repos/airbnb/enzyme/issues/1025/labels{/name}","comments_url":"https://api.github.com/repos/airbnb/enzyme/issues/1025/comments","events_url":"https://api.github.com/repos/airbnb/enzyme/issues/1025/events","html_url":"https://github.com/airbnb/enzyme/issues/1025","id":241463635,"node_id":"MDU6SXNzdWUyNDE0NjM2MzU=","number":1025,"title":"What is the correct way to test state dependant \"connected\" HOC's","user":{"login":"PavelPolyakov","id":839290,"node_id":"MDQ6VXNlcjgzOTI5MA==","avatar_url":"https://avatars0.githubusercontent.com/u/839290?v=4","gravatar_id":"","url":"https://api.github.com/users/PavelPolyakov","html_url":"https://github.com/PavelPolyakov","followers_url":"https://api.github.com/users/PavelPolyakov/followers","following_url":"https://api.github.com/users/PavelPolyakov/following{/other_user}","gists_url":"https://api.github.com/users/PavelPolyakov/gists{/gist_id}","starred_url":"https://api.github.com/users/PavelPolyakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PavelPolyakov/subscriptions","organizations_url":"https://api.github.com/users/PavelPolyakov/orgs","repos_url":"https://api.github.com/users/PavelPolyakov/repos","events_url":"https://api.github.com/users/PavelPolyakov/events{/privacy}","received_events_url":"https://api.github.com/users/PavelPolyakov/received_events","type":"User","site_admin":false},"labels":[{"id":284995846,"node_id":"MDU6TGFiZWwyODQ5OTU4NDY=","url":"https://api.github.com/repos/airbnb/enzyme/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2017-07-08T16:22:47Z","updated_at":"2018-12-05T09:07:23Z","closed_at":"2017-07-14T06:01:24Z","author_association":"NONE","body":"There are several issues where people ask how to test `connected` components, as it's not possible to `setState` for them. The answer is - we need export pure and connected components separately.\r\n([here](https://github.com/airbnb/enzyme/issues/98) and [here](https://github.com/airbnb/enzyme/issues/431), for example)\r\n\r\nHowever, there is another situation, which I've reproduced in this repository:\r\nhttps://github.com/PavelPolyakov/enzyme-HOC-setState\r\n\r\nImagine we have a HOC which needs to grab some information from the redux store and attach it to the `WrappedComponent`. In the examples case it attaches the pokemon info:\r\nhttps://github.com/PavelPolyakov/enzyme-HOC-setState/blob/master/src/appHOC.js\r\n\r\nAt the same time, there is a `state` condition in the `HOC` code itself, let's say we start some procedure on `componentWillMount` and don't want to show anything till this procedure is done. The procedure is asynchronous.\r\n\r\nIt's not possible to do neither:\r\n```\r\nroot.find('AppHOC').setState({});\r\n```\r\nnor\r\n```\r\nroot.find('AppHOC').state();\r\n```\r\nThe latest could be very useful, so it's possible to write a proper async wait for the state.\r\n\r\nWhat is the correct way to test it? Let's say I want to mock the asynchronous procedure during the tests. However, I'm not able to `setState` on the component directly, because this is not a root component. From the other point - I can not export it as a pure component, as it depends on the `WrappedComponent`.\r\n\r\nAs a dirty solution, it is possible to put your `expect` inside the `setTimeout`, however, it means we wait for the max time:\r\nhttps://github.com/PavelPolyakov/enzyme-HOC-setState/blob/master/src/__tests__/appHOC.test.js\r\n\r\n@ljharb , what would be the suggested way to overcome this situation using `enzyme` ?\r\n\r\nRegards,"},"comment":{"url":"https://api.github.com/repos/airbnb/enzyme/issues/comments/444411649","html_url":"https://github.com/airbnb/enzyme/issues/1025#issuecomment-444411649","issue_url":"https://api.github.com/repos/airbnb/enzyme/issues/1025","id":444411649,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDQxMTY0OQ==","user":{"login":"dschinkel","id":338798,"node_id":"MDQ6VXNlcjMzODc5OA==","avatar_url":"https://avatars3.githubusercontent.com/u/338798?v=4","gravatar_id":"","url":"https://api.github.com/users/dschinkel","html_url":"https://github.com/dschinkel","followers_url":"https://api.github.com/users/dschinkel/followers","following_url":"https://api.github.com/users/dschinkel/following{/other_user}","gists_url":"https://api.github.com/users/dschinkel/gists{/gist_id}","starred_url":"https://api.github.com/users/dschinkel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dschinkel/subscriptions","organizations_url":"https://api.github.com/users/dschinkel/orgs","repos_url":"https://api.github.com/users/dschinkel/repos","events_url":"https://api.github.com/users/dschinkel/events{/privacy}","received_events_url":"https://api.github.com/users/dschinkel/received_events","type":"User","site_admin":false},"created_at":"2018-12-05T09:07:23Z","updated_at":"2018-12-05T09:07:23Z","author_association":"NONE","body":"Cool.\r\n\r\nYou must be referring to what I call \"Component/Acceptance\" tests (outside tests in BDD).  I still use shallow for those but that's my approach.  I've found a way to do that which works and sharing that in my course."}}
{"actor":{"display_login":"dschinkel"}}