Skip to content

Commit dfc8711

Browse files
authored
chore: use @fast-check/jest (#13493)
1 parent b027fb0 commit dfc8711

10 files changed

+191
-217
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"eslint-plugin-markdown": "^3.0.0",
4343
"eslint-plugin-prettier": "^4.0.0",
4444
"execa": "^5.0.0",
45-
"fast-check": "^3.0.0",
4645
"find-process": "^1.4.1",
4746
"glob": "^8.0.0",
4847
"globby": "^11.0.1",

packages/diff-sequences/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"./package.json": "./package.json"
2929
},
3030
"devDependencies": {
31+
"@fast-check/jest": "^1.3.0",
3132
"benchmark": "^2.1.4",
32-
"diff": "^5.0.0",
33-
"fast-check": "^3.0.0"
33+
"diff": "^5.0.0"
3434
},
3535
"publishConfig": {
3636
"access": "public"

packages/diff-sequences/src/__tests__/index.property.test.ts

Lines changed: 59 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import fc from 'fast-check';
9+
import {fc, it} from '@fast-check/jest';
1010
import diff from '../';
1111

1212
const findCommonItems = (a: Array<string>, b: Array<string>): Array<string> => {
@@ -55,81 +55,71 @@ const isSubsequenceOf = (
5555
return iSub === subsequence.length;
5656
};
5757

58-
it('should be reflexive', () => {
59-
fc.assert(
60-
fc.property(fc.array(fc.char()), a => {
61-
expect(findCommonItems(a, a)).toEqual(a);
62-
}),
63-
);
58+
it.prop([fc.array(fc.char())])('should be reflexive', a => {
59+
expect(findCommonItems(a, a)).toEqual(a);
6460
});
6561

66-
it('should find the same number of common items when switching the inputs', () => {
62+
it.prop([fc.array(fc.char()), fc.array(fc.char())])(
63+
'should find the same number of common items when switching the inputs',
6764
// findCommonItems is not symmetric as:
6865
// > findCommonItems(["Z"," "], [" ","Z"]) = [" "]
6966
// > findCommonItems([" ","Z"], ["Z"," "]) = ["Z"]
70-
fc.assert(
71-
fc.property(fc.array(fc.char()), fc.array(fc.char()), (a, b) => {
72-
const commonItems = findCommonItems(a, b);
73-
const symmetricCommonItems = findCommonItems(b, a);
74-
expect(symmetricCommonItems).toHaveLength(commonItems.length);
75-
}),
76-
);
77-
});
67+
(a, b) => {
68+
const commonItems = findCommonItems(a, b);
69+
const symmetricCommonItems = findCommonItems(b, a);
70+
expect(symmetricCommonItems).toHaveLength(commonItems.length);
71+
},
72+
);
7873

79-
it('should have at most the length of its inputs', () => {
80-
fc.assert(
81-
fc.property(fc.array(fc.char()), fc.array(fc.char()), (a, b) => {
82-
const commonItems = findCommonItems(a, b);
83-
expect(commonItems.length).toBeLessThanOrEqual(a.length);
84-
expect(commonItems.length).toBeLessThanOrEqual(b.length);
85-
}),
86-
);
87-
});
74+
it.prop([fc.array(fc.char()), fc.array(fc.char())])(
75+
'should have at most the length of its inputs',
76+
(a, b) => {
77+
const commonItems = findCommonItems(a, b);
78+
expect(commonItems.length).toBeLessThanOrEqual(a.length);
79+
expect(commonItems.length).toBeLessThanOrEqual(b.length);
80+
},
81+
);
8882

89-
it('should have at most the same number of each character as its inputs', () => {
90-
fc.assert(
91-
fc.property(fc.array(fc.char()), fc.array(fc.char()), (a, b) => {
92-
const commonItems = findCommonItems(a, b);
93-
const commonCount = extractCount(commonItems);
94-
const aCount = extractCount(a);
95-
for (const [item, count] of commonCount) {
96-
const countOfItemInA = aCount.get(item) ?? 0;
97-
expect(countOfItemInA).toBeGreaterThanOrEqual(count);
98-
}
99-
}),
100-
);
101-
});
83+
it.prop([fc.array(fc.char()), fc.array(fc.char())])(
84+
'should have at most the same number of each character as its inputs',
85+
(a, b) => {
86+
const commonItems = findCommonItems(a, b);
87+
const commonCount = extractCount(commonItems);
88+
const aCount = extractCount(a);
89+
for (const [item, count] of commonCount) {
90+
const countOfItemInA = aCount.get(item) ?? 0;
91+
expect(countOfItemInA).toBeGreaterThanOrEqual(count);
92+
}
93+
},
94+
);
10295

103-
it('should be a subsequence of its inputs', () => {
104-
fc.assert(
105-
fc.property(fc.array(fc.char()), fc.array(fc.char()), (a, b) => {
106-
const commonItems = findCommonItems(a, b);
107-
expect(isSubsequenceOf(commonItems, a)).toBe(true);
108-
expect(isSubsequenceOf(commonItems, b)).toBe(true);
109-
}),
110-
);
111-
});
96+
it.prop([fc.array(fc.char()), fc.array(fc.char())])(
97+
'should be a subsequence of its inputs',
98+
(a, b) => {
99+
const commonItems = findCommonItems(a, b);
100+
expect(isSubsequenceOf(commonItems, a)).toBe(true);
101+
expect(isSubsequenceOf(commonItems, b)).toBe(true);
102+
},
103+
);
112104

113-
it('should be no-op when passing common items', () => {
114-
fc.assert(
115-
fc.property(fc.array(fc.char()), fc.array(fc.char()), (a, b) => {
116-
const commonItems = findCommonItems(a, b);
117-
expect(findCommonItems(a, commonItems)).toEqual(commonItems);
118-
expect(findCommonItems(commonItems, a)).toEqual(commonItems);
119-
}),
120-
);
121-
});
105+
it.prop([fc.array(fc.char()), fc.array(fc.char())])(
106+
'should be no-op when passing common items',
107+
(a, b) => {
108+
const commonItems = findCommonItems(a, b);
109+
expect(findCommonItems(a, commonItems)).toEqual(commonItems);
110+
expect(findCommonItems(commonItems, a)).toEqual(commonItems);
111+
},
112+
);
122113

123-
it('should find the exact common items when one array is subarray of the other', () => {
124-
fc.assert(
125-
fc.property(fc.array(fc.array(fc.char())), data => {
126-
const allData = flatten(data); // [...data[0], ...data[1], ...data[2], ...data[3], ...]
127-
const partialData = flatten(data.filter((_, i) => i % 2 === 1)); // [...data[1], ...data[3], ...]
128-
const commonItems = findCommonItems(allData, partialData);
129-
// We have:
130-
// 1. commonItems contains at least all the items of partialData as they are in allData too
131-
// 2. commonItems cannot contain more items than its inputs (partialData for instance)
132-
expect(commonItems.length).toBeGreaterThanOrEqual(partialData.length);
133-
}),
134-
);
135-
});
114+
it.prop([fc.array(fc.array(fc.char()))])(
115+
'should find the exact common items when one array is subarray of the other',
116+
data => {
117+
const allData = flatten(data); // [...data[0], ...data[1], ...data[2], ...data[3], ...]
118+
const partialData = flatten(data.filter((_, i) => i % 2 === 1)); // [...data[1], ...data[3], ...]
119+
const commonItems = findCommonItems(allData, partialData);
120+
// We have:
121+
// 1. commonItems contains at least all the items of partialData as they are in allData too
122+
// 2. commonItems cannot contain more items than its inputs (partialData for instance)
123+
expect(commonItems.length).toBeGreaterThanOrEqual(partialData.length);
124+
},
125+
);

packages/expect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"jest-util": "workspace:^"
2727
},
2828
"devDependencies": {
29+
"@fast-check/jest": "^1.3.0",
2930
"@jest/test-utils": "workspace:^",
3031
"@tsd/typescript": "~4.8.2",
3132
"chalk": "^4.0.0",
32-
"fast-check": "^3.0.0",
3333
"immutable": "^4.0.0",
3434
"tsd-lite": "^0.6.0"
3535
},

packages/expect/src/__tests__/__arbitraries__/sharedSettings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
import fc from 'fast-check';
9+
import {fc} from '@fast-check/jest';
1010

1111
// settings for anything arbitrary
1212
export const anythingSettings = {

packages/expect/src/__tests__/matchers-toContain.property.test.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,44 @@
66
*
77
*/
88

9-
import fc from 'fast-check';
9+
import {fc, it} from '@fast-check/jest';
1010
import expect from '../';
1111
import {
1212
anythingSettings,
1313
assertSettings,
1414
} from './__arbitraries__/sharedSettings';
1515

1616
describe('toContain', () => {
17-
it('should always find the value when inside the array', () => {
18-
fc.assert(
19-
fc.property(
20-
fc.array(fc.anything(anythingSettings)),
21-
fc.array(fc.anything(anythingSettings)),
22-
fc.anything(anythingSettings).filter(v => !Number.isNaN(v)),
23-
(startValues, endValues, v) => {
24-
// Given: startValues, endValues arrays and v value (not NaN)
25-
expect([...startValues, v, ...endValues]).toContain(v);
26-
},
27-
),
28-
assertSettings,
29-
);
30-
});
17+
it.prop(
18+
[
19+
fc.array(fc.anything(anythingSettings)),
20+
fc.array(fc.anything(anythingSettings)),
21+
fc.anything(anythingSettings).filter(v => !Number.isNaN(v)),
22+
],
23+
assertSettings,
24+
)(
25+
'should always find the value when inside the array',
26+
(startValues, endValues, v) => {
27+
// Given: startValues, endValues arrays and v value (not NaN)
28+
expect([...startValues, v, ...endValues]).toContain(v);
29+
},
30+
);
3131

32-
it('should not find the value if it has been cloned into the array', () => {
33-
fc.assert(
34-
fc.property(
35-
fc.array(fc.anything(anythingSettings)),
36-
fc.array(fc.anything(anythingSettings)),
37-
fc.clone(fc.anything(anythingSettings), 2),
38-
(startValues, endValues, [a, b]) => {
39-
// Given: startValues, endValues arrays
40-
// and [a, b] equal, but not the same values
41-
// with `typeof a === 'object && a !== null`
42-
fc.pre(typeof a === 'object' && a !== null);
43-
expect([...startValues, a, ...endValues]).not.toContain(b);
44-
},
45-
),
46-
assertSettings,
47-
);
48-
});
32+
it.prop(
33+
[
34+
fc.array(fc.anything(anythingSettings)),
35+
fc.array(fc.anything(anythingSettings)),
36+
fc.clone(fc.anything(anythingSettings), 2),
37+
],
38+
assertSettings,
39+
)(
40+
'should not find the value if it has been cloned into the array',
41+
(startValues, endValues, [a, b]) => {
42+
// Given: startValues, endValues arrays
43+
// and [a, b] equal, but not the same values
44+
// with `typeof a === 'object && a !== null`
45+
fc.pre(typeof a === 'object' && a !== null);
46+
expect([...startValues, a, ...endValues]).not.toContain(b);
47+
},
48+
);
4949
});

packages/expect/src/__tests__/matchers-toContainEqual.property.test.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@
66
*
77
*/
88

9-
import fc from 'fast-check';
9+
import {fc, it} from '@fast-check/jest';
1010
import expect from '../';
1111
import {
1212
anythingSettings,
1313
assertSettings,
1414
} from './__arbitraries__/sharedSettings';
1515

1616
describe('toContainEqual', () => {
17-
it('should always find the value when inside the array', () => {
18-
fc.assert(
19-
fc.property(
20-
fc.array(fc.anything(anythingSettings)),
21-
fc.array(fc.anything(anythingSettings)),
22-
fc.anything(anythingSettings),
23-
(startValues, endValues, v) => {
24-
// Given: startValues, endValues arrays and v any value
25-
expect([...startValues, v, ...endValues]).toContainEqual(v);
26-
},
27-
),
28-
assertSettings,
29-
);
30-
});
17+
it.prop(
18+
[
19+
fc.array(fc.anything(anythingSettings)),
20+
fc.array(fc.anything(anythingSettings)),
21+
fc.anything(anythingSettings),
22+
],
23+
assertSettings,
24+
)(
25+
'should always find the value when inside the array',
26+
(startValues, endValues, v) => {
27+
// Given: startValues, endValues arrays and v any value
28+
expect([...startValues, v, ...endValues]).toContainEqual(v);
29+
},
30+
);
3131

32-
it('should always find the value when cloned inside the array', () => {
33-
fc.assert(
34-
fc.property(
35-
fc.array(fc.anything(anythingSettings)),
36-
fc.array(fc.anything(anythingSettings)),
37-
fc.clone(fc.anything(anythingSettings), 2),
38-
(startValues, endValues, [a, b]) => {
39-
// Given: startValues, endValues arrays
40-
// and [a, b] identical values
41-
expect([...startValues, a, ...endValues]).toContainEqual(b);
42-
},
43-
),
44-
assertSettings,
45-
);
46-
});
32+
it.prop(
33+
[
34+
fc.array(fc.anything(anythingSettings)),
35+
fc.array(fc.anything(anythingSettings)),
36+
fc.clone(fc.anything(anythingSettings), 2),
37+
],
38+
assertSettings,
39+
)(
40+
'should always find the value when cloned inside the array',
41+
(startValues, endValues, [a, b]) => {
42+
// Given: startValues, endValues arrays
43+
// and [a, b] identical values
44+
expect([...startValues, a, ...endValues]).toContainEqual(b);
45+
},
46+
);
4747
});

0 commit comments

Comments
 (0)