-
-
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
fix #145 contains
does not fail on string input
#148
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,38 @@ describe('shallow', () => { | |
expect(wrapper.contains(b)).to.equal(true); | ||
}); | ||
|
||
it('should work with strings', () => { | ||
const wrapper = shallow(<div>foo</div>); | ||
|
||
expect(wrapper.contains('foo')).to.equal(true); | ||
expect(wrapper.contains('bar')).to.equal(false); | ||
}); | ||
|
||
it('should work with numbers', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a counter-test here, that in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. Actually I did wrong comparison with numbers. Fixed it. |
||
const wrapper = shallow(<div>{1}</div>); | ||
|
||
expect(wrapper.contains(1)).to.equal(true); | ||
expect(wrapper.contains(2)).to.equal(false); | ||
expect(wrapper.contains('1')).to.equal(false); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add another test or two that make sure this works properly for multiple nested levels? const wrapper = shallow(
<div>
<div>
<div>{5}</div>
</div>
<div>
);
expect(wrapper.contains(5)).to.equal(true);
expect(wrapper.contains(<div>{5}</div>)).to.equal(true); |
||
|
||
it('should work with nested strings & numbers', () => { | ||
const wrapper = shallow( | ||
<div> | ||
<div> | ||
<div>{5}</div> | ||
</div> | ||
<div>foo</div> | ||
</div> | ||
); | ||
|
||
expect(wrapper.contains('foo')).to.equal(true); | ||
expect(wrapper.contains(<div>foo</div>)).to.equal(true); | ||
|
||
expect(wrapper.contains(5)).to.equal(true); | ||
expect(wrapper.contains(<div>{5}</div>)).to.equal(true); | ||
}); | ||
|
||
}); | ||
|
||
describe('.equals(node)', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb I just noticed this, but should we use a lib for
Object.keys
instead of assuming it's available?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's pretty safe to assume it's available.
Object.keys
has really wide support. On the browser side you'd have to use less than IE9, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keysOn node side, it's been included since at least 0.10. I'm not sure exactly when it was added to V8, but I think being in 0.10 makes it more than safe to use natively
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's part of ES5 - node 0.8 and higher, and IE 9 and higher have it.
However, if you want to support older engines (which I strongly recommend!) you can use the https://npmjs.com/object-keys module :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that since react requires ES5 and above, it is safe to conclude that at least an es5-shim will be loaded in any environment enzyme will be used...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM