Skip to content

Commit

Permalink
Merge pull request #147 from astorije/astorije/include
Browse files Browse the repository at this point in the history
Add tests around `include` and deep equality
  • Loading branch information
astorije authored May 29, 2018
2 parents d73902d + 358a7eb commit 31a3515
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ rules:
- always
semi-spacing: error
semi-style: error
sort-keys: error
sort-vars: error
space-before-blocks: error
space-before-function-paren:
Expand Down
43 changes: 43 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ describe('chai-immutable', function () { // eslint-disable-line prefer-arrow-cal
it('should pass using `not` given an inexisting property', function () { // eslint-disable-line prefer-arrow-callback
expect(nestedObj).not.to.have.nested.property(['y', 'z']);
expect(nestedObj).not.to.have.nested.deep.property(['y', 'z']);
expect(nestedObj).not.to.have.property('a', new Map({ x: 2 }));
});

it('should pass using `not` given an inexisting property and value', function () { // eslint-disable-line prefer-arrow-callback
Expand Down Expand Up @@ -972,6 +973,46 @@ describe('chai-immutable', function () { // eslint-disable-line prefer-arrow-cal
});
});

describe('include assertion', function () { // eslint-disable-line prefer-arrow-callback
const map1 = new Map({ a: 1 });
const map2 = new Map({ b: 2 });
const list = new List([map1, map2]);
const map = new Map({ foo: map1, bar: map2 });

it('should ensure deep equality', function () { // eslint-disable-line prefer-arrow-callback
assert.include(list, map1);
assert.include(list, new Map({ a: 1 }));

assert.include(map, map1);
assert.include(map, new Map({ a: 1 }));
});

it('should not treat partial collections as sub-collections', function () { // eslint-disable-line prefer-arrow-callback
fail(() => assert.include(map, new Map({ foo: map1 })));
fail(() => assert.include(map, new Map({ foo: map1, bar: map2 })));
});
});

describe('notInclude assertion', function () { // eslint-disable-line prefer-arrow-callback
const map1 = new Map({ a: 1 });
const map2 = new Map({ b: 2 });
const list = new List([map1, map2]);
const map = new Map({ foo: map1, bar: map2 });

it('should ensure deep equality', function () { // eslint-disable-line prefer-arrow-callback
assert.notInclude(map, new Map({ foo: map1 }));
assert.notInclude(map, new Map({ foo: map1, bar: map2 }));
});

it('should not treat partial collections as sub-collections', function () { // eslint-disable-line prefer-arrow-callback
fail(() => assert.notInclude(list, map1));
fail(() => assert.notInclude(list, new Map({ a: 1 })));

fail(() => assert.notInclude(map, map1));
fail(() => assert.notInclude(map, new Map({ a: 1 })));
});
});

describe('property assertions', function () { // eslint-disable-line prefer-arrow-callback
const obj = Immutable.fromJS({ x: 1 });
const nestedObj = Immutable.fromJS({ x: 1, y: { x: 2, y: 3 } });
Expand Down Expand Up @@ -1009,6 +1050,8 @@ describe('chai-immutable', function () { // eslint-disable-line prefer-arrow-cal
assert.notDeepPropertyVal(obj, 'z', 1);
assert.notPropertyVal(obj, 'x', 42);
assert.notDeepPropertyVal(obj, 'x', 42);
assert.notPropertyVal(obj, 'foo', new Map({ bar: 'baz' }));
assert.notDeepPropertyVal(obj, 'foo', new Map({ bar: 'baz' }));
});

it('should fail for existing property and value using `not`', function () { // eslint-disable-line prefer-arrow-callback
Expand Down

0 comments on commit 31a3515

Please sign in to comment.