Skip to content

Commit

Permalink
1. Added fix for checking null or unfined during equality checking
Browse files Browse the repository at this point in the history
2. Added tests for the check
  • Loading branch information
anilreddykatta committed Apr 11, 2017
1 parent 6a50e0d commit 69fee54
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions __tests__/Record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ describe('Record', () => {
expect(t1.equals(t2));
});

it('if compared against undefined or null should return false', () => {
const MyType = Record({ a: 1, b: 2 });
const t1 = new MyType();
expect(t1.equals(undefined)).toBeFalsy();
expect(t1.equals(null)).toBeFalsy();
});

it('merges in Objects and other Records', () => {
let Point2 = Record({x: 0, y: 0});
let Point3 = Record({x: 0, y: 0, z: 0});
Expand Down
6 changes: 4 additions & 2 deletions dist/immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5235,8 +5235,10 @@ Record.prototype.toString = function toString () {
};

Record.prototype.equals = function equals (other) {
return this === other ||
(this._keys === other._keys && recordSeq(this).equals(recordSeq(other)));
return other &&
(this === other ||
(this._keys === other._keys &&
recordSeq(this).equals(recordSeq(other))));
};

Record.prototype.hashCode = function hashCode () {
Expand Down
6 changes: 3 additions & 3 deletions dist/immutable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ export class Record {
}

equals(other) {
return this === other ||
(this._keys === other._keys && recordSeq(this).equals(recordSeq(other)));
return other &&
(this === other ||
(this._keys === other._keys &&
recordSeq(this).equals(recordSeq(other))));
}

hashCode() {
Expand Down

0 comments on commit 69fee54

Please sign in to comment.