Skip to content

Commit

Permalink
feat(core): add referenceNotEqual TDD implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubzitny committed Apr 14, 2019
1 parent fe9a5ce commit 307c9f3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions chai-immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,31 @@
}
};

/**
* ### .referenceNotEqual(actual, expected)
*
* Asserts that the reference of `actual` is not equivalent to the reference of
* `expected`. This method preserves the original behavior of chai's notEqual.
*
* Reasons for this are described in #210.
*
* ```js
* const a = List.of(1, 2, 3);
* const b = a
* const c = List.of(1, 2, 3);
* assert.referenceNotEqual(a, b); // false
* assert.referenceNotEqual(a, c); // true
* ```
*
* @name referenceEqual
* @param {Collection} actual
* @param {Collection} expected
* @namespace Assert
* @api public
*/

assert.referenceNotEqual = originalNotEqual;

/**
* ### .sizeOf(collection, length)
*
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,22 @@ describe('chai-immutable', function() {
});
});

describe('referenceNotEqual assertion', function() {
it('should pass for different immutable collections with equal values', function() {
const list1 = List.of(1, 2, 3);
const list2 = List.of(1, 2, 3);

assert.referenceNotEqual(list1, list2);
});

it('should not pass for different immutable collections with equal values', function() {
const list1 = List.of(1, 2, 3);
const list2 = list1;

fail(() => assert.referenceNotEqual(list1, list2));
});
});

describe('unoverridden strictEqual and deepEqual assertions', function() {
it('should pass given equal values', function() {
assert.strictEqual(list3, List.of(1, 2, 3));
Expand Down

0 comments on commit 307c9f3

Please sign in to comment.