Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

equals should skip null and undefined props #656

Closed
vadimdemedes opened this issue Nov 4, 2016 · 2 comments
Closed

equals should skip null and undefined props #656

vadimdemedes opened this issue Nov 4, 2016 · 2 comments

Comments

@vadimdemedes
Copy link
Contributor

vadimdemedes commented Nov 4, 2016

This is a continuation of #151, which fixed the skipping of nodes, but the same issue exists for props.

Here's an example to demonstrate the problem:

import React from 'react';
import {shallow} from 'enzyme';

const Box = ({className}) => (
  <div className={className}/>
);

shallow(<Box/>).equals(<div/>); //=> false
shallow(<Box/>).equals(<div className={undefined}/>); //=> true
shallow(<Box className="awesome"/>).equals(<div className="awesome"/>); //=> true

nodeEqual() fails, because it expects className={undefined} property in the other component (<div/>). This is happening here https://github.com/airbnb/enzyme/blob/master/src/Utils.js#L94. Tested using the latest enzyme available on npm (2.5.1).

I think this case should be covered in enzyme by ignoring null and undefined props, which is what React does too. If everyone agrees, I can submit a PR to fix it ;)

@ljharb
Copy link
Member

ljharb commented Nov 4, 2016

That does seem reasonable, but let's get thoughts from more collabs before making the PR.

@aweary
Copy link
Collaborator

aweary commented Nov 5, 2016

👍 sounds good to me. If React ignores it, we should too.

ljharb pushed a commit to vadimdemedes/enzyme that referenced this issue Sep 23, 2017
 - `.find` with an object with `undefined` values should throw

Fixes enzymejs#656.
ljharb pushed a commit to vadimdemedes/enzyme that referenced this issue Sep 26, 2017
 - `.find` with an object with `undefined` values should throw

Fixes enzymejs#656.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants