{"action":"closed","issue":{"url":"https://api.github.com/repos/airbnb/enzyme/issues/465","repository_url":"https://api.github.com/repos/airbnb/enzyme","labels_url":"https://api.github.com/repos/airbnb/enzyme/issues/465/labels{/name}","comments_url":"https://api.github.com/repos/airbnb/enzyme/issues/465/comments","events_url":"https://api.github.com/repos/airbnb/enzyme/issues/465/events","html_url":"https://github.com/airbnb/enzyme/issues/465","id":161432295,"number":465,"title":"API differences between render and mount/shallow","user":{"login":"geowarin","id":1045636,"avatar_url":"https://avatars.githubusercontent.com/u/1045636?v=3","gravatar_id":"","url":"https://api.github.com/users/geowarin","html_url":"https://github.com/geowarin","followers_url":"https://api.github.com/users/geowarin/followers","following_url":"https://api.github.com/users/geowarin/following{/other_user}","gists_url":"https://api.github.com/users/geowarin/gists{/gist_id}","starred_url":"https://api.github.com/users/geowarin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geowarin/subscriptions","organizations_url":"https://api.github.com/users/geowarin/orgs","repos_url":"https://api.github.com/users/geowarin/repos","events_url":"https://api.github.com/users/geowarin/events{/privacy}","received_events_url":"https://api.github.com/users/geowarin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/airbnb/enzyme/labels/Render","name":"Render","color":"bfd4f2"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-06-21T13:09:02Z","updated_at":"2016-06-28T17:12:31Z","closed_at":"2016-06-28T17:12:31Z","body":"This is more of a question than an issue. I'm trying to see where you guys want to go with the `render()` function.\r\nI like it but the API feels awkward sometimes.\r\n\r\nFor example, it is not possible to do this:\r\n\r\n```js\r\nimport {render} from 'enzyme';\r\n\r\nconst component = render(<MyComponent />);\r\nconst options = component.find('option').map(o => o.text());\r\n```\r\n\r\nError:\r\n```\r\nTypeError: o.text is not a function\r\n```\r\n\r\nIn cherrio's documenation, the pattern to map elements is:\r\n\r\n```js\r\n$('li').map(function(i, el) {\r\n  return $(this).text();\r\n}).get().join(' ');\r\n```\r\n\r\nSo the workaround seems to be:\r\n\r\n```js\r\nimport cheerio from 'cheerio';\r\n\r\ncomponent.find('option').map((i, el) => cheerio(el).text()).get()\r\n```\r\n\r\nwhich is kind of ugly and contrasts with the nice APIs of `render()` and `mount()`.\r\n\r\nA solution would be to return a wrapper in the render function instead of `cheerio.load(html).root()`.\r\n\r\nSomething along the lines of:\r\n\r\n```js\r\nclass CheerioWrapper {\r\n\r\n  constructor(root) {\r\n    this.root = root;\r\n  }\r\n\r\n  map(mapper) {\r\n    return this.root.map((i,e) => mapper(cheerio(e))).get();\r\n  }\r\n\r\n  find(what) {\r\n    return new CheerioWrapper(this.root.find(what));\r\n  }\r\n\r\n  // etc...\r\n}\r\n\r\nfunction render(node) {\r\n  const html = renderToStaticMarkup(node);\r\n  return new CheerioWrapper(cheerio.load(html).root());\r\n}\r\n```\r\n\r\nThis looks like some work but it would have the advantage of proposing a unified API for `mount()`, `shallow()` and `render()`.\r\n\r\nSo the question is: what is your roadmap for the `render` function ?"}}
{"actor":{"display_login":"Aweary"}}