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

Make R.eqProps safe for null/undefined arguments #2943

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions source/eqProps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _curry3 from './internal/_curry3';
import equals from './equals';
import prop from './prop';


/**
Expand All @@ -23,7 +24,7 @@ import equals from './equals';
* R.eqProps('a', o1, o2); //=> false
* R.eqProps('c', o1, o2); //=> true
*/
var eqProps = _curry3(function eqProps(prop, obj1, obj2) {
return equals(obj1[prop], obj2[prop]);
var eqProps = _curry3(function eqProps(key, obj1, obj2) {
return equals(prop(key, obj1), prop(key, obj2));
});
export default eqProps;
15 changes: 15 additions & 0 deletions test/eqProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,19 @@ describe('eqProps', function() {
eq(R.eqProps('value', {value: new Just([42])}, {value: new Just([42])}), true);
});

it('can handle null or undefined object', function() {
eq(R.eqProps('value', {value: 0}, null), false);
eq(R.eqProps('value', null, {value: 0}), false);
eq(R.eqProps('value', {value: 0}, undefined), false);
eq(R.eqProps('value', undefined, {value: 0}), false);
eq(R.eqProps('value', undefined, {value: undefined}), true);
eq(R.eqProps('value', null, {value: undefined}), true);
eq(R.eqProps('value', {value: undefined}, undefined), true);
eq(R.eqProps('value', {value: undefined}, null), true);
eq(R.eqProps('value', {}, null), true);
eq(R.eqProps('value', {}, undefined), true);
eq(R.eqProps('value', null, {}), true);
eq(R.eqProps('value', undefined, {}), true);
});

});