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

fix #145 contains does not fail on string input #148

Merged
merged 3 commits into from
Feb 1, 2016

Conversation

smacker
Copy link
Contributor

@smacker smacker commented Jan 29, 2016

Also I added a check for number:

    it('should work with numbers', () => {
      const wrapper = shallow(<div>1</div>);

      expect(wrapper.contains(1)).to.equal(true);
      expect(wrapper.contains(2)).to.equal(false);
    });

expect(wrapper.contains('bar')).to.equal(false);
});

it('should work with numbers', () => {
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Collaborator

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?

Copy link
Contributor

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

Copy link
Member

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 :-)

Copy link
Collaborator

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...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@smacker
Copy link
Contributor Author

smacker commented Feb 1, 2016

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.

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

Successfully merging this pull request may close these issues.

4 participants