{"action":"created","comment":{"url":"https://api.github.com/repos/airbnb/enzyme/pulls/comments/227183433","pull_request_review_id":167164234,"id":227183433,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNzE4MzQzMw==","diff_hunk":"@@ -9,32 +9,188 @@ a host device.\n This can be difficult when you want your test suite to run with typical Continuous Integration servers\n such as Travis.\n \n-A pure JS mock of React Native exists and can solve this problem in the majority of use cases.\n+To use enzyme to test React Native, you currently need to configure an adapter, and load an emulated DOM.\n \n-To install it, run:\n+## Configuring an Adapter\n \n-```bash\n-npm i --save-dev react-native-mock\n+While a React Native adapter is [in discussion](https://github.com/airbnb/enzyme/issues/1436),\n+a standard adapter may be used, such as \"enzyme-adapter-react-16\":\n+\n+```\n+import Adapter from \"enzyme-adapter-react-16\";\n+\n+Enzyme.configure({ adapter: new Adapter() });\n+```\n+\n+## Loading an emulated DOM with JSDOM\n+\n+To use enzyme's `deep` until a React Native adapter exists, an emulated DOM must be loaded.\n+\n+While some have had success with [react-native-mock-renderer](https://github.com/Root-App/react-native-mock-render),\n+the recommended approach is to use [https://github.com/tmpvar/jsdom](JSDOM),\n+as documented for enzyme at the [JSDOM](https://airbnb.io/enzyme/docs/guides/jsdom.html) documentation page.\n+\n+JSDOM will allow all of the `enzyme` behavior you would expect, and it will result in reasonable snapshots if\n+used in a Jest snapshot test.\n+\n+## Using enzyme's find when lacking className props\n+\n+It is worth noting that React Native allows for a [testID](https://facebook.github.io/react-native/docs/view#testid)\n+prop, that can be used a selector similar to `className` in standard React:\n+\n+```javascript\n+    <View key={key} style={styles.todo} testID=\"todo-item\">\n+      <Text testID=\"todo-title\" style={styles.title}>{todo.title}</Text>\n+    </View>\n ```\n \n-Requiring or importing the `/mock` entry file of this project will input the mock `react-native`\n-export into the require cache, so that your application uses the mock instead.\n+```javascript\n+  expect(\n+    wrapper.findWhere(node => node.prop(\"testID\") === \"todo-item\"),\n+  ).toExist();\n+```\n+\n+## Example configuration for Jest\n+\n+To perform the necessary configuration in your testing framework, it is recommended to use a setup script,\n+such as with Jest's `setupTestFrameworkScriptFile` setting.\n \n-If you are using a test runner such as mocha, this means that you can use the `--require` flag\n-before you run your test suite, and enzyme should \"just work\":\n+Create or update a `jest.config.js` file at the root of your project to include the `setupTestFrameworkScriptFile` setting:\n \n+```javascript\n+// jest.config.js\n \n-### Mocha CLI\n+module.exports = {\n+  // Load setup-tests.js before test execution\n+  setupTestFrameworkScriptFile: \"<rootDir>setup-tests.js\",\n \n-```bash\n-mocha --require react-native-mock/mock --recursive path/to/test/dir\n+  // ...\n+};\n ```\n \n-### In Code\n+Then create or update the file specified in `setupTestFrameworkScriptFile`, in this case `setup-tests.js` in the project root:\n+\n+```javascript\n+// setup-tests.js\n+\n+import \"react-native\";\n+import \"jest-enzyme\";\n+import Adapter from \"enzyme-adapter-react-16\";\n+import Enzyme from \"enzyme\";\n+\n+/**\n+ * Set up DOM in node.js environment for Enzyme to mount to\n+ */\n+const { JSDOM } = require(\"jsdom\");\n+\n+const jsdom = new JSDOM(\"<!doctype html><html><body></body></html>\");\n+const { window } = jsdom;\n+\n+function copyProps(src, target) {\n+  const props = Object.getOwnPropertyNames(src)\n+    .filter(prop => typeof target[prop] === \"undefined\")","path":"docs/guides/react-native.md","position":null,"original_position":95,"commit_id":"b9e7fec3950ffef15771ba2df5573842af8fea62","original_commit_id":"860e0ed075d0b843787a12f66d79e4ecd383dcbd","user":{"login":"shawnaxsom","id":607938,"node_id":"MDQ6VXNlcjYwNzkzOA==","avatar_url":"https://avatars1.githubusercontent.com/u/607938?v=4","gravatar_id":"","url":"https://api.github.com/users/shawnaxsom","html_url":"https://github.com/shawnaxsom","followers_url":"https://api.github.com/users/shawnaxsom/followers","following_url":"https://api.github.com/users/shawnaxsom/following{/other_user}","gists_url":"https://api.github.com/users/shawnaxsom/gists{/gist_id}","starred_url":"https://api.github.com/users/shawnaxsom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shawnaxsom/subscriptions","organizations_url":"https://api.github.com/users/shawnaxsom/orgs","repos_url":"https://api.github.com/users/shawnaxsom/repos","events_url":"https://api.github.com/users/shawnaxsom/events{/privacy}","received_events_url":"https://api.github.com/users/shawnaxsom/received_events","type":"User","site_admin":false},"body":"I've updated all the double quotes in the page to single quotes","created_at":"2018-10-23T00:32:08Z","updated_at":"2018-10-23T00:32:08Z","html_url":"https://github.com/airbnb/enzyme/pull/1873#discussion_r227183433","pull_request_url":"https://api.github.com/repos/airbnb/enzyme/pulls/1873","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/airbnb/enzyme/pulls/comments/227183433"},"html":{"href":"https://github.com/airbnb/enzyme/pull/1873#discussion_r227183433"},"pull_request":{"href":"https://api.github.com/repos/airbnb/enzyme/pulls/1873"}},"in_reply_to_id":227169789},"pull_request":{"url":"https://api.github.com/repos/airbnb/enzyme/pulls/1873","id":224511493,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI0NTExNDkz","html_url":"https://github.com/airbnb/enzyme/pull/1873","diff_url":"https://github.com/airbnb/enzyme/pull/1873.diff","patch_url":"https://github.com/airbnb/enzyme/pull/1873.patch","issue_url":"https://api.github.com/repos/airbnb/enzyme/issues/1873","number":1873,"state":"open","locked":false,"title":"Documentation update for testing React Native using jsdom","user":{"login":"shawnaxsom","id":607938,"node_id":"MDQ6VXNlcjYwNzkzOA==","avatar_url":"https://avatars1.githubusercontent.com/u/607938?v=4","gravatar_id":"","url":"https://api.github.com/users/shawnaxsom","html_url":"https://github.com/shawnaxsom","followers_url":"https://api.github.com/users/shawnaxsom/followers","following_url":"https://api.github.com/users/shawnaxsom/following{/other_user}","gists_url":"https://api.github.com/users/shawnaxsom/gists{/gist_id}","starred_url":"https://api.github.com/users/shawnaxsom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shawnaxsom/subscriptions","organizations_url":"https://api.github.com/users/shawnaxsom/orgs","repos_url":"https://api.github.com/users/shawnaxsom/repos","events_url":"https://api.github.com/users/shawnaxsom/events{/privacy}","received_events_url":"https://api.github.com/users/shawnaxsom/received_events","type":"User","site_admin":false},"body":"As discussed in #1375, I was also unable to get React Native testing working with Jest/Enzyme with the current documentation instructions.\r\n\r\nI see that a React Native adapter is still being discussed in #1436, but I found that some users have had success with jsdom. I was able to get both react-native-mock-renderer and jsdom working, but react-native-mock-renderer didn't result in very clear snapshots when using Jest snapshot testing.\r\n\r\nI have therefore provided some instructions here for how I was able to get React Native testing working with jsdom, and I added some examples from the [React Native boilerplate project](https://github.com/ProminentEdge/mobile-boilerplate) where it is currently working. I decided to leave in a few helpful tips of other issues I encountered along the way as well.","created_at":"2018-10-21T01:24:01Z","updated_at":"2018-10-23T00:32:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d6083040ae5ee49bf50037b97155949e813f50b0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":285514405,"node_id":"MDU6TGFiZWwyODU1MTQ0MDU=","url":"https://api.github.com/repos/airbnb/enzyme/labels/docs","name":"docs","color":"eb6420","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/airbnb/enzyme/pulls/1873/commits","review_comments_url":"https://api.github.com/repos/airbnb/enzyme/pulls/1873/comments","review_comment_url":"https://api.github.com/repos/airbnb/enzyme/pulls/comments{/number}","comments_url":"https://api.github.com/repos/airbnb/enzyme/issues/1873/comments","statuses_url":"https://api.github.com/repos/airbnb/enzyme/statuses/b9e7fec3950ffef15771ba2df5573842af8fea62","head":{"label":"shawnaxsom:feature/react-native-documentation","ref":"feature/react-native-documentation","sha":"b9e7fec3950ffef15771ba2df5573842af8fea62","user":{"login":"shawnaxsom","id":607938,"node_id":"MDQ6VXNlcjYwNzkzOA==","avatar_url":"https://avatars1.githubusercontent.com/u/607938?v=4","gravatar_id":"","url":"https://api.github.com/users/shawnaxsom","html_url":"https://github.com/shawnaxsom","followers_url":"https://api.github.com/users/shawnaxsom/followers","following_url":"https://api.github.com/users/shawnaxsom/following{/other_user}","gists_url":"https://api.github.com/users/shawnaxsom/gists{/gist_id}","starred_url":"https://api.github.com/users/shawnaxsom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shawnaxsom/subscriptions","organizations_url":"https://api.github.com/users/shawnaxsom/orgs","repos_url":"https://api.github.com/users/shawnaxsom/repos","events_url":"https://api.github.com/users/shawnaxsom/events{/privacy}","received_events_url":"https://api.github.com/users/shawnaxsom/received_events","type":"User","site_admin":false},"repo":{"id":153957023,"node_id":"MDEwOlJlcG9zaXRvcnkxNTM5NTcwMjM=","name":"enzyme","full_name":"shawnaxsom/enzyme","private":false,"owner":{"login":"shawnaxsom","id":607938,"node_id":"MDQ6VXNlcjYwNzkzOA==","avatar_url":"https://avatars1.githubusercontent.com/u/607938?v=4","gravatar_id":"","url":"https://api.github.com/users/shawnaxsom","html_url":"https://github.com/shawnaxsom","followers_url":"https://api.github.com/users/shawnaxsom/followers","following_url":"https://api.github.com/users/shawnaxsom/following{/other_user}","gists_url":"https://api.github.com/users/shawnaxsom/gists{/gist_id}","starred_url":"https://api.github.com/users/shawnaxsom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shawnaxsom/subscriptions","organizations_url":"https://api.github.com/users/shawnaxsom/orgs","repos_url":"https://api.github.com/users/shawnaxsom/repos","events_url":"https://api.github.com/users/shawnaxsom/events{/privacy}","received_events_url":"https://api.github.com/users/shawnaxsom/received_events","type":"User","site_admin":false},"html_url":"https://github.com/shawnaxsom/enzyme","description":"JavaScript Testing utilities for React","fork":true,"url":"https://api.github.com/repos/shawnaxsom/enzyme","forks_url":"https://api.github.com/repos/shawnaxsom/enzyme/forks","keys_url":"https://api.github.com/repos/shawnaxsom/enzyme/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shawnaxsom/enzyme/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shawnaxsom/enzyme/teams","hooks_url":"https://api.github.com/repos/shawnaxsom/enzyme/hooks","issue_events_url":"https://api.github.com/repos/shawnaxsom/enzyme/issues/events{/number}","events_url":"https://api.github.com/repos/shawnaxsom/enzyme/events","assignees_url":"https://api.github.com/repos/shawnaxsom/enzyme/assignees{/user}","branches_url":"https://api.github.com/repos/shawnaxsom/enzyme/branches{/branch}","tags_url":"https://api.github.com/repos/shawnaxsom/enzyme/tags","blobs_url":"https://api.github.com/repos/shawnaxsom/enzyme/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shawnaxsom/enzyme/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shawnaxsom/enzyme/git/refs{/sha}","trees_url":"https://api.github.com/repos/shawnaxsom/enzyme/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shawnaxsom/enzyme/statuses/{sha}","languages_url":"https://api.github.com/repos/shawnaxsom/enzyme/languages","stargazers_url":"https://api.github.com/repos/shawnaxsom/enzyme/stargazers","contributors_url":"https://api.github.com/repos/shawnaxsom/enzyme/contributors","subscribers_url":"https://api.github.com/repos/shawnaxsom/enzyme/subscribers","subscription_url":"https://api.github.com/repos/shawnaxsom/enzyme/subscription","commits_url":"https://api.github.com/repos/shawnaxsom/enzyme/commits{/sha}","git_commits_url":"https://api.github.com/repos/shawnaxsom/enzyme/git/commits{/sha}","comments_url":"https://api.github.com/repos/shawnaxsom/enzyme/comments{/number}","issue_comment_url":"https://api.github.com/repos/shawnaxsom/enzyme/issues/comments{/number}","contents_url":"https://api.github.com/repos/shawnaxsom/enzyme/contents/{+path}","compare_url":"https://api.github.com/repos/shawnaxsom/enzyme/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shawnaxsom/enzyme/merges","archive_url":"https://api.github.com/repos/shawnaxsom/enzyme/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shawnaxsom/enzyme/downloads","issues_url":"https://api.github.com/repos/shawnaxsom/enzyme/issues{/number}","pulls_url":"https://api.github.com/repos/shawnaxsom/enzyme/pulls{/number}","milestones_url":"https://api.github.com/repos/shawnaxsom/enzyme/milestones{/number}","notifications_url":"https://api.github.com/repos/shawnaxsom/enzyme/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shawnaxsom/enzyme/labels{/name}","releases_url":"https://api.github.com/repos/shawnaxsom/enzyme/releases{/id}","deployments_url":"https://api.github.com/repos/shawnaxsom/enzyme/deployments","created_at":"2018-10-20T23:24:54Z","updated_at":"2018-10-21T01:10:10Z","pushed_at":"2018-10-23T00:30:28Z","git_url":"git://github.com/shawnaxsom/enzyme.git","ssh_url":"git@github.com:shawnaxsom/enzyme.git","clone_url":"https://github.com/shawnaxsom/enzyme.git","svn_url":"https://github.com/shawnaxsom/enzyme","homepage":"https://airbnb.io/enzyme/","size":4911,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"airbnb:master","ref":"master","sha":"3cdf88e6be11e7b54bc7877954a6438682d4becd","user":{"login":"airbnb","id":698437,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5ODQzNw==","avatar_url":"https://avatars3.githubusercontent.com/u/698437?v=4","gravatar_id":"","url":"https://api.github.com/users/airbnb","html_url":"https://github.com/airbnb","followers_url":"https://api.github.com/users/airbnb/followers","following_url":"https://api.github.com/users/airbnb/following{/other_user}","gists_url":"https://api.github.com/users/airbnb/gists{/gist_id}","starred_url":"https://api.github.com/users/airbnb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/airbnb/subscriptions","organizations_url":"https://api.github.com/users/airbnb/orgs","repos_url":"https://api.github.com/users/airbnb/repos","events_url":"https://api.github.com/users/airbnb/events{/privacy}","received_events_url":"https://api.github.com/users/airbnb/received_events","type":"Organization","site_admin":false},"repo":{"id":45942274,"node_id":"MDEwOlJlcG9zaXRvcnk0NTk0MjI3NA==","name":"enzyme","full_name":"airbnb/enzyme","private":false,"owner":{"login":"airbnb","id":698437,"node_id":"MDEyOk9yZ2FuaXphdGlvbjY5ODQzNw==","avatar_url":"https://avatars3.githubusercontent.com/u/698437?v=4","gravatar_id":"","url":"https://api.github.com/users/airbnb","html_url":"https://github.com/airbnb","followers_url":"https://api.github.com/users/airbnb/followers","following_url":"https://api.github.com/users/airbnb/following{/other_user}","gists_url":"https://api.github.com/users/airbnb/gists{/gist_id}","starred_url":"https://api.github.com/users/airbnb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/airbnb/subscriptions","organizations_url":"https://api.github.com/users/airbnb/orgs","repos_url":"https://api.github.com/users/airbnb/repos","events_url":"https://api.github.com/users/airbnb/events{/privacy}","received_events_url":"https://api.github.com/users/airbnb/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/airbnb/enzyme","description":"JavaScript Testing utilities for React","fork":false,"url":"https://api.github.com/repos/airbnb/enzyme","forks_url":"https://api.github.com/repos/airbnb/enzyme/forks","keys_url":"https://api.github.com/repos/airbnb/enzyme/keys{/key_id}","collaborators_url":"https://api.github.com/repos/airbnb/enzyme/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/airbnb/enzyme/teams","hooks_url":"https://api.github.com/repos/airbnb/enzyme/hooks","issue_events_url":"https://api.github.com/repos/airbnb/enzyme/issues/events{/number}","events_url":"https://api.github.com/repos/airbnb/enzyme/events","assignees_url":"https://api.github.com/repos/airbnb/enzyme/assignees{/user}","branches_url":"https://api.github.com/repos/airbnb/enzyme/branches{/branch}","tags_url":"https://api.github.com/repos/airbnb/enzyme/tags","blobs_url":"https://api.github.com/repos/airbnb/enzyme/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/airbnb/enzyme/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/airbnb/enzyme/git/refs{/sha}","trees_url":"https://api.github.com/repos/airbnb/enzyme/git/trees{/sha}","statuses_url":"https://api.github.com/repos/airbnb/enzyme/statuses/{sha}","languages_url":"https://api.github.com/repos/airbnb/enzyme/languages","stargazers_url":"https://api.github.com/repos/airbnb/enzyme/stargazers","contributors_url":"https://api.github.com/repos/airbnb/enzyme/contributors","subscribers_url":"https://api.github.com/repos/airbnb/enzyme/subscribers","subscription_url":"https://api.github.com/repos/airbnb/enzyme/subscription","commits_url":"https://api.github.com/repos/airbnb/enzyme/commits{/sha}","git_commits_url":"https://api.github.com/repos/airbnb/enzyme/git/commits{/sha}","comments_url":"https://api.github.com/repos/airbnb/enzyme/comments{/number}","issue_comment_url":"https://api.github.com/repos/airbnb/enzyme/issues/comments{/number}","contents_url":"https://api.github.com/repos/airbnb/enzyme/contents/{+path}","compare_url":"https://api.github.com/repos/airbnb/enzyme/compare/{base}...{head}","merges_url":"https://api.github.com/repos/airbnb/enzyme/merges","archive_url":"https://api.github.com/repos/airbnb/enzyme/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/airbnb/enzyme/downloads","issues_url":"https://api.github.com/repos/airbnb/enzyme/issues{/number}","pulls_url":"https://api.github.com/repos/airbnb/enzyme/pulls{/number}","milestones_url":"https://api.github.com/repos/airbnb/enzyme/milestones{/number}","notifications_url":"https://api.github.com/repos/airbnb/enzyme/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/airbnb/enzyme/labels{/name}","releases_url":"https://api.github.com/repos/airbnb/enzyme/releases{/id}","deployments_url":"https://api.github.com/repos/airbnb/enzyme/deployments","created_at":"2015-11-10T21:45:38Z","updated_at":"2018-10-22T21:08:46Z","pushed_at":"2018-10-23T00:30:31Z","git_url":"git://github.com/airbnb/enzyme.git","ssh_url":"git@github.com:airbnb/enzyme.git","clone_url":"https://github.com/airbnb/enzyme.git","svn_url":"https://github.com/airbnb/enzyme","homepage":"https://airbnb.io/enzyme/","size":5397,"stargazers_count":15545,"watchers_count":15545,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":1669,"mirror_url":null,"archived":false,"open_issues_count":132,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":1669,"open_issues":132,"watchers":15545,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/airbnb/enzyme/pulls/1873"},"html":{"href":"https://github.com/airbnb/enzyme/pull/1873"},"issue":{"href":"https://api.github.com/repos/airbnb/enzyme/issues/1873"},"comments":{"href":"https://api.github.com/repos/airbnb/enzyme/issues/1873/comments"},"review_comments":{"href":"https://api.github.com/repos/airbnb/enzyme/pulls/1873/comments"},"review_comment":{"href":"https://api.github.com/repos/airbnb/enzyme/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/airbnb/enzyme/pulls/1873/commits"},"statuses":{"href":"https://api.github.com/repos/airbnb/enzyme/statuses/b9e7fec3950ffef15771ba2df5573842af8fea62"}},"author_association":"NONE"}}
{"actor":{"display_login":"shawnaxsom"}}