-
-
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
Conversation
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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a counter-test here, that in <div>1</div>
, wrapper.contains('1')
is false
?
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.
oh. Actually I did wrong comparison with numbers. Fixed it.
return leftKeys.length === Object.keys(right).length; | ||
|
||
if (typeof a !== 'string' && typeof a !== 'number') { | ||
return leftKeys.length === Object.keys(right).length; |
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/keys
On 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
Tests added. It's safe to assume Object.keys is available, if you run it inside IE8, you definitely have some polyfills. es5-shim, or babel-polyfill, because otherwise almost nothing will work. |
fix #145 `contains` does not fail on string input
Also I added a check for number: