From 358a7eb9506fab56b9bdfff2f83b9dfec4e0e241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Mon, 28 May 2018 20:39:44 -0400 Subject: [PATCH] Add tests around `include` and deep equality --- .eslintrc.yml | 1 - test/test.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index e442eca..04eccdf 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -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: diff --git a/test/test.js b/test/test.js index ee3682f..bc70102 100644 --- a/test/test.js +++ b/test/test.js @@ -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 @@ -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 } }); @@ -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