{"action":"created","issue":{"url":"https://api.github.com/repos/airbnb/enzyme/issues/432","repository_url":"https://api.github.com/repos/airbnb/enzyme","labels_url":"https://api.github.com/repos/airbnb/enzyme/issues/432/labels{/name}","comments_url":"https://api.github.com/repos/airbnb/enzyme/issues/432/comments","events_url":"https://api.github.com/repos/airbnb/enzyme/issues/432/events","html_url":"https://github.com/airbnb/enzyme/pull/432","id":157919400,"number":432,"title":"Loose contains and default props","user":{"login":"jkimbo","id":691952,"avatar_url":"https://avatars.githubusercontent.com/u/691952?v=3","gravatar_id":"","url":"https://api.github.com/users/jkimbo","html_url":"https://github.com/jkimbo","followers_url":"https://api.github.com/users/jkimbo/followers","following_url":"https://api.github.com/users/jkimbo/following{/other_user}","gists_url":"https://api.github.com/users/jkimbo/gists{/gist_id}","starred_url":"https://api.github.com/users/jkimbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkimbo/subscriptions","organizations_url":"https://api.github.com/users/jkimbo/orgs","repos_url":"https://api.github.com/users/jkimbo/repos","events_url":"https://api.github.com/users/jkimbo/events{/privacy}","received_events_url":"https://api.github.com/users/jkimbo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/airbnb/enzyme/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/airbnb/enzyme/labels/PATCH","name":"PATCH","color":"bfe5bf"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-06-01T14:21:57Z","updated_at":"2016-06-30T21:34:58Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/airbnb/enzyme/pulls/432","html_url":"https://github.com/airbnb/enzyme/pull/432","diff_url":"https://github.com/airbnb/enzyme/pull/432.diff","patch_url":"https://github.com/airbnb/enzyme/pull/432.patch"},"body":"Came across this issue today where the `.containsMatchingElement` function gets tripped up with default props. If a custom component has a default prop that is overridden when it's rendered you have to add that override to the component your matching against for `.containsMatchingElement` to work. I've added a minimal failing test for both the shallow and full dom render wrappers to illustrate it.\r\n\r\nIn my mind the `.containsMatchingElement` (and it's siblings) should not care that a default prop is different between the rendered component and the matching one since that is not what I'm testing but I can see why that is the case since at the point of checking React doesn't differentiate. Any thoughts on this?\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/airbnb/enzyme/issues/comments/229795828","html_url":"https://github.com/airbnb/enzyme/pull/432#issuecomment-229795828","issue_url":"https://api.github.com/repos/airbnb/enzyme/issues/432","id":229795828,"user":{"login":"jkimbo","id":691952,"avatar_url":"https://avatars.githubusercontent.com/u/691952?v=3","gravatar_id":"","url":"https://api.github.com/users/jkimbo","html_url":"https://github.com/jkimbo","followers_url":"https://api.github.com/users/jkimbo/followers","following_url":"https://api.github.com/users/jkimbo/following{/other_user}","gists_url":"https://api.github.com/users/jkimbo/gists{/gist_id}","starred_url":"https://api.github.com/users/jkimbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkimbo/subscriptions","organizations_url":"https://api.github.com/users/jkimbo/orgs","repos_url":"https://api.github.com/users/jkimbo/repos","events_url":"https://api.github.com/users/jkimbo/events{/privacy}","received_events_url":"https://api.github.com/users/jkimbo/received_events","type":"User","site_admin":false},"created_at":"2016-06-30T21:34:58Z","updated_at":"2016-06-30T21:34:58Z","body":"@nfcampos apologies for the late reply to this, I've been on holiday for the past couple of weeks.\r\n\r\nSo, while I understand your argument around correctness, I would argue that as a test writer my assumption would be that the props that I am not asserting against would not affect my tests. I am not trying to say that `containsMatchingElement` should match an element **irrespective of its props** but that it should match an element **with the props that I am checking for** and no more. The docs on `containsMatchingElement` specifically say:\r\n\r\n> ...element in the wraper **looks like** the expected element...\r\n\r\nwhich to me indicates that it is using a heuristic to determine if an element **looks like** what is being rendered. I would argue that that heuristic should ignore default props when matching.\r\n\r\nHere is a more complete example which I hope illustrates my point a bit better.\r\n\r\nThe following should pass:\r\n\r\n```js\r\n      class TestComponent extends React.Component {\r\n        render() {\r\n          return (<div>Hello World</div>);\r\n        }\r\n      }\r\n      TestComponent.defaultProps = {\r\n        fizz: true,\r\n      };\r\n\r\n      const wrapper = shallow(\r\n        <div>\r\n          <TestComponent foo=\"buzz\" className=\"bar\" />\r\n        </div>\r\n      );\r\n      expect(wrapper.containsMatchingElement(\r\n        <TestComponent className=\"bar\" />\r\n      )).to.equal(true);\r\n```\r\n\r\nHowever if I set the default prop of `foo` on `TestComponent` to something other than `buzz`:\r\n\r\n```js\r\n      TestComponent.defaultProps = {\r\n        fizz: true,\r\n        foo: 'bar',\r\n      };\r\n```\r\n\r\nthen the test will fail. In my eyes that's not the expected because `<TestComponent className=\"bar\" />` **looks like** `<TestComponent foo=\"buzz\" className=\"bar\" />`"}}
{"actor":{"display_login":"jkimbo"}}