Skip to content

Commit

Permalink
property test toStrictEqual vs deepStrictEqual
Browse files Browse the repository at this point in the history
also, import expect so that property tests do not need rebuilds
  • Loading branch information
jeysal committed Nov 12, 2019
1 parent 6f42949 commit f4558fe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
anythingSettings,
assertSettings,
} from './__arbitraries__/sharedSettings';
import expect from '..';

describe('toContain', () => {
it('should always find the value when inside the array', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
anythingSettings,
assertSettings,
} from './__arbitraries__/sharedSettings';
import expect from '..';

describe('toContainEqual', () => {
it('should always find the value when inside the array', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
anythingSettings,
assertSettings,
} from './__arbitraries__/sharedSettings';
import expect from '..';

describe('toEqual', () => {
it('should be reflexive', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,31 @@
*
*/

import assert from 'assert';
import fc from 'fast-check';
import {
anythingSettings,
assertSettings,
} from './__arbitraries__/sharedSettings';
import expect from '..';

describe('toStrictEqual', () => {
const safeExpectStrictEqual = (a, b) => {
try {
expect(a).toStrictEqual(b);
return true;
} catch (err) {
return false;
}
};
const safeAssertDeepStrictEqual = (a, b) => {
try {
assert.deepStrictEqual(a, b);
return true;
} catch (err) {
return false;
}
};
it('should be reflexive', () => {
fc.assert(
fc.property(fc.dedup(fc.anything(anythingSettings), 2), ([a, b]) => {
Expand All @@ -24,14 +42,6 @@ describe('toStrictEqual', () => {
});

it('should be symmetric', () => {
const safeExpectStrictEqual = (a, b) => {
try {
expect(a).toStrictEqual(b);
return true;
} catch (err) {
return false;
}
};
fc.assert(
fc.property(
fc.anything(anythingSettings),
Expand All @@ -46,4 +56,18 @@ describe('toStrictEqual', () => {
assertSettings,
);
});

it('should be equivalent to Node deepStrictEqual', () => {
fc.assert(
fc.property(
fc.anything(anythingSettings),
fc.anything(anythingSettings),
(a, b) => {
expect(safeExpectStrictEqual(a, b)).toBe(
safeAssertDeepStrictEqual(a, b),
);
},
),
);
});
});

0 comments on commit f4558fe

Please sign in to comment.