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

.to.deep.equal() performs unexpectedly with empty object #15

bruderstein opened this issue Feb 22, 2015 · 2 comments · Fixed by #17


Copy link

@bruderstein bruderstein commented Feb 22, 2015

Due to Hoek's deepEqual funtion only checking existing properties in the "left" object, thereby allowing the right object to be a superset of the left, means that an empty object always passes.

If you have the following

var result = testInstance.getCurrentUser();
expect(result).to.deep.equal({ user: 'steve', id: 14 });

If getCurrentUser() returns an empty object, this will pass, which is probably unexpected.
You get a "better" result, by doing the (unintuitive) reverse:

expect({ user: 'steve', id: 14 }).to.deep.equal(result);

This fails if the user or id properties are not equal, but passes if result has extra properties.

The initial "quick fix" could be to just swap the arguments to Hoek.deepEqual, which would be "better" behaviour, although that still needs to be made clear in the docs.


This comment has been minimized.

Copy link

@cjihrig cjihrig commented Feb 22, 2015

Thanks for reporting this. This sounds more like an issue with Hoek. Can you open an issue over there? Once fixed, Code can be updated with the fix.

@cjihrig cjihrig closed this Feb 22, 2015
@hueniverse hueniverse reopened this Feb 22, 2015

This comment has been minimized.

Copy link

@hueniverse hueniverse commented Feb 22, 2015

Better to keep this open until it is resolved in hoek and verified here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.