{"action":"created","issue":{"url":"https://api.github.com/repos/airbnb/enzyme/issues/1624","repository_url":"https://api.github.com/repos/airbnb/enzyme","labels_url":"https://api.github.com/repos/airbnb/enzyme/issues/1624/labels{/name}","comments_url":"https://api.github.com/repos/airbnb/enzyme/issues/1624/comments","events_url":"https://api.github.com/repos/airbnb/enzyme/issues/1624/events","html_url":"https://github.com/airbnb/enzyme/issues/1624","id":315163720,"node_id":"MDU6SXNzdWUzMTUxNjM3MjA=","number":1624,"title":"setState() can only be called on class components -- but my component is a class","user":{"login":"jcollum","id":704514,"node_id":"MDQ6VXNlcjcwNDUxNA==","avatar_url":"https://avatars2.githubusercontent.com/u/704514?v=4","gravatar_id":"","url":"https://api.github.com/users/jcollum","html_url":"https://github.com/jcollum","followers_url":"https://api.github.com/users/jcollum/followers","following_url":"https://api.github.com/users/jcollum/following{/other_user}","gists_url":"https://api.github.com/users/jcollum/gists{/gist_id}","starred_url":"https://api.github.com/users/jcollum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcollum/subscriptions","organizations_url":"https://api.github.com/users/jcollum/orgs","repos_url":"https://api.github.com/users/jcollum/repos","events_url":"https://api.github.com/users/jcollum/events{/privacy}","received_events_url":"https://api.github.com/users/jcollum/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-04-17T17:44:42Z","updated_at":"2018-11-12T14:35:07Z","closed_at":"2018-04-17T23:54:14Z","author_association":"NONE","body":"### Current behavior\r\n\r\nThe docs: https://github.com/airbnb/enzyme/blob/master/docs/api/ShallowWrapper/setState.md\r\n\r\nThe docs say to do this: \r\n\r\n```\r\nconst wrapper = shallow(<Foo />);\r\n...\r\nwrapper.setState({ name: 'bar' });\r\n```\r\n\r\nMy class:  `class PrivacyInquiry extends React.Component {`. The class renders fine on the page. \r\n\r\nThis is the test: \r\n\r\n```\r\nit('Shows additional info box if category is Complaint or Question ', (done) => {\r\n\r\n...\r\n    const privacyPage = shallow(<PrivacyInquiry country=\"us\" language=\"en\" path=\"/\" localizations={localizations} />);\r\n    privacyPage.setState({ selectedCategory: 'Complaint' }, ()=>{\r\n      const textArea = privacyPage.find('textarea#additionalInfo');\r\n      expect(textArea.length).toEqual(1);\r\n      done();\r\n    });\r\n\r\n  });\r\n```\r\n\r\nWhen I run the test it fails on the `setState` line: \r\n\r\n```\r\n ShallowWrapper::setState() can only be called on class components\r\n```\r\n\r\nIt looks like my component is a class. It looks like I'm doing exactly what the docs say to do. It seems that everything I'm doing is normal React stuff. I have another test that just tests the rendering of `PrivacyInquiry` and looks for some items on the page and that test passes. That test uses `mount` though.  \r\n\r\n### Expected behavior\r\n\r\n`setState` changes state \r\n\r\n### Your environment\r\n```\r\n✗ node --version\r\nv6.9.5\r\n```\r\n\r\nIs the node version the problem? I can't really change it\r\n\r\n#### API\r\n\r\n- [x] shallow\r\n- [ ] mount\r\n- [ ] render\r\n\r\n#### Version\r\n\r\n| library         | version\r\n| ---------------- | -------\r\n| Enzyme           | 3.3\r\n| React            |  16.2\r\n\r\n#### Adapter\r\n\r\n- [x] enzyme-adapter-react-16\r\n- [ ] enzyme-adapter-react-15\r\n- [ ] enzyme-adapter-react-15.4\r\n- [ ] enzyme-adapter-react-14\r\n- [ ] enzyme-adapter-react-13\r\n- [ ] enzyme-adapter-react-helper\r\n- [ ] others ( ) \r\n"},"comment":{"url":"https://api.github.com/repos/airbnb/enzyme/issues/comments/437903209","html_url":"https://github.com/airbnb/enzyme/issues/1624#issuecomment-437903209","issue_url":"https://api.github.com/repos/airbnb/enzyme/issues/1624","id":437903209,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNzkwMzIwOQ==","user":{"login":"DenisBubnov","id":37404527,"node_id":"MDQ6VXNlcjM3NDA0NTI3","avatar_url":"https://avatars3.githubusercontent.com/u/37404527?v=4","gravatar_id":"","url":"https://api.github.com/users/DenisBubnov","html_url":"https://github.com/DenisBubnov","followers_url":"https://api.github.com/users/DenisBubnov/followers","following_url":"https://api.github.com/users/DenisBubnov/following{/other_user}","gists_url":"https://api.github.com/users/DenisBubnov/gists{/gist_id}","starred_url":"https://api.github.com/users/DenisBubnov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DenisBubnov/subscriptions","organizations_url":"https://api.github.com/users/DenisBubnov/orgs","repos_url":"https://api.github.com/users/DenisBubnov/repos","events_url":"https://api.github.com/users/DenisBubnov/events{/privacy}","received_events_url":"https://api.github.com/users/DenisBubnov/received_events","type":"User","site_admin":false},"created_at":"2018-11-12T14:35:07Z","updated_at":"2018-11-12T14:35:07Z","author_association":"NONE","body":"> The same issue.\r\n> So, in the root app, Ex: app.js\r\n> to export look like\r\n> `class App extends React.Component { // todo }`\r\n> `export default hot(module)(withHttpErrorHandler(withErrorAlert(App)));`\r\n> \r\n> please help me how to run test\r\n\r\nDo you have the solution of your problem?"}}
{"actor":{"display_login":"DenisBubnov"}}