-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 nodes
#151
Comments
@roadhump I agree. We could extend our This may require couple of caveats... would we consider would we consider We may want to consider the pros/cons of each case. |
I'd say an empty array should be the same as |
I found out that https://github.com/algolia/react-element-to-jsx-string and https://github.com/bkonkle/jsx-chai works pretty well as replacement of current So my test case now import React from 'react';
import chai from 'chai'
import chaiEnzyme from 'chai-enzyme';
import chaiJSX from 'jsx-chai';
chai.use(chaiEnzyme());
chai.use(chaiJSX);
const expect = chai.expect
import {shallow} from 'enzyme';
const ComponentFoo = ({name, onClick}) => (
<div>
<em ref="em" onClick={onClick}>{name}</em>
<strong>{[null]}</strong>
<ComponentBar name={name} />
</div>)
const ComponentBar = ({name, onClick}) => (<i>{name}</i>)
describe('Component', () => {
it('works', () => {
const onClick = () => alert('click');
const jsx = (<ComponentFoo name="lol" onClick={onClick} />)
const dom = shallow(jsx);
expect(dom.get(0)).to.be.eql(<div><em ref="em" onClick={onClick}>lol</em><strong /><ComponentBar name="lol" /></div>);
expect(dom.find('ComponentBar').get(0)).to.be.eql(<ComponentBar name="lol" />);
expect(dom.find('em').get(0)).to.be.eql(<em ref="em" onClick={onClick}>lol</em>);
})
}) So I suppose, probably it would be easier to replace current |
I don't want to bring in a dependency to the jsx-string library because I think comparing stringified versions of these structures is fundamentally the wrong approach. I do think our For the most part, I'm comfortable saying that things that react effectively "ignores" do not need to be specified in the case of equality checks. The primary cases being This means the following things are all considered equal: <div>{null}{"Foo"}</div>
<div>{[null]}{"Foo"}</div>
<div>Foo</div>
<div>{[null, "Foo"]}</div>
<div>{[false, "Foo"]}</div>
<div>{["Foo"]}</div> |
This issue has been already fixed. |
There is a common pattern to use ternary operators to create conditions inside JSX templates.
I expect
equals
should return true when compare these templatesBut now it expects null value and second template must be only
I suppose this comparison should skip null and undefined values in such cases. What do you think?
The text was updated successfully, but these errors were encountered: