diff --git a/modules/Expectation.js b/modules/Expectation.js index bfbe4c9..1d9502b 100644 --- a/modules/Expectation.js +++ b/modules/Expectation.js @@ -1,5 +1,5 @@ -import deepEqual from 'deep-equal' -import isRegExp from 'is-regexp' +import isEqual from 'is-equal' +import isRegExp from 'is-regex' import assert from './assert' import { isSpy } from './SpyUtils' import { functionThrows, arrayContains, stringContains, isArray, isFunction, isA } from './TestUtils' @@ -65,7 +65,7 @@ class Expectation { toEqual(value, message) { try { assert( - deepEqual(this.actual, value), + isEqual(this.actual, value), (message || 'Expected %s to equal %s'), this.actual, value @@ -83,7 +83,7 @@ class Expectation { toNotEqual(value, message) { assert( - !deepEqual(this.actual, value), + !isEqual(this.actual, value), (message || 'Expected %s to not equal %s'), this.actual, value @@ -334,7 +334,7 @@ class Expectation { assert( spy.calls.some(function (call) { - return deepEqual(call.arguments, expectedArgs) + return isEqual(call.arguments, expectedArgs) }), 'spy was never called with %s', expectedArgs diff --git a/modules/TestUtils.js b/modules/TestUtils.js index fcd1d60..730619f 100644 --- a/modules/TestUtils.js +++ b/modules/TestUtils.js @@ -1,5 +1,5 @@ -import deepEqual from 'deep-equal' -import isRegExp from 'is-regexp' +import isEqual from 'is-equal' +import isRegExp from 'is-regex' /** * Returns true if the given function throws the given value @@ -41,7 +41,7 @@ export function functionThrows(fn, context, args, value) { */ export function arrayContains(array, value, comparator) { if (comparator == null) - comparator = deepEqual + comparator = isEqual return array.some(function (item) { return comparator(item, value) !== false diff --git a/modules/__tests__/toEqual-test.js b/modules/__tests__/toEqual-test.js index 8904351..6700634 100644 --- a/modules/__tests__/toEqual-test.js +++ b/modules/__tests__/toEqual-test.js @@ -8,6 +8,33 @@ describe('toEqual', function () { }).toThrow(/Expected 'actual' to equal 'expected'/) }) + it('works when object has circular reference' , function () { + function circular() { + this.circularRef = this + } + + const a = new circular() + const b = new circular() + + expect(a).toEqual(b) + }) + + it('works with Map', function () { + const a = new Map() + a.set('key', 'value') + + const b = new Map() + b.set('key', 'value') + + expect(a).toEqual(b) + }) + + it('works with Set', function () { + const a = new Set('a') + const b = new Set('a') + expect(a).toEqual(b) + }) + it('shows diff', function () { try { expect('actual').toEqual('expected') diff --git a/modules/__tests__/toNotEqual-test.js b/modules/__tests__/toNotEqual-test.js new file mode 100644 index 0000000..20d49d1 --- /dev/null +++ b/modules/__tests__/toNotEqual-test.js @@ -0,0 +1,20 @@ +/*eslint-env mocha */ +import expect from '../index' + +describe('toNotEqual', function () { + it('works with Map', function () { + const a = new Map() + a.set('key', 'value') + + const b = new Map() + b.set('key', 'another value') + + expect(a).toNotEqual(b) + }) + + it('works with Set', function () { + const a = new Set('a') + const b = new Set('b') + expect(a).toNotEqual(b) + }) +}) diff --git a/package.json b/package.json index 2744235..cd25a73 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "description": "Write better assertions", "main": "lib/index", "dependencies": { - "deep-equal": "^1.0.1", - "is-regexp": "^1.0.0", + "is-equal": "^1.3.0", + "is-regex": "^1.0.3", "object-inspect": "^1.0.2" }, "devDependencies": {