Skip to content

Commit ac5ba4c

Browse files
committed
test(explorer): remove property based testing
There were usefull when developping, but: - they are more than 100 times slower than classic jest tests - the part covered don't justify such slowdown
1 parent 6eddba9 commit ac5ba4c

File tree

4 files changed

+25
-93
lines changed

4 files changed

+25
-93
lines changed

mithril-explorer/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,10 @@ upgrade: clean install
6565
react-chartjs-2@latest \
6666
react-dom@latest \
6767
react-redux@latest \
68-
@fast-check/jest@latest \
6968
@testing-library/jest-dom@latest \
7069
@testing-library/react@latest \
7170
eslint@latest \
7271
eslint-config-next@latest \
73-
@fast-check/jest@latest \
7472
fantasticon@latest \
7573
jest@latest \
7674
jest-environment-jsdom@latest \

mithril-explorer/__tests__/DownloadImmutableFormInput.test.js

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { fireEvent, render, screen } from "@testing-library/react";
2-
import { test, fc } from "@fast-check/jest";
32
import "@testing-library/jest-dom";
43
import { DownloadImmutableFormInput } from "#/Artifacts/CardanoDbV2SnapshotsList/DownloadButton";
54

6-
const maxImmutable = 100000;
5+
const maxImmutable = 100_000;
76

87
function setup(max) {
98
const utils = render(<DownloadImmutableFormInput max={max} />);
109
return {
11-
// Note: in `fast-check` tests `screen.getByRole("spinbutton")` find two elements for a reason I don't understand, so
12-
// I'm using getAllByRole and selecting the first one to avoid the error.
13-
input: screen.getAllByRole("spinbutton")[0],
10+
input: screen.getByRole("spinbutton"),
1411
...utils,
1512
};
1613
}
@@ -29,35 +26,32 @@ describe("DownloadImmutableFormInput", () => {
2926
expect(input.value).toBe("");
3027
});
3128

32-
test.prop({
33-
immutable_file_number: fc.nat({
34-
max: maxImmutable,
35-
}),
36-
})("Immutable below or equal to max allowed", ({ immutable_file_number }) => {
37-
const { input } = setup(maxImmutable);
38-
fireEvent.change(input, {
39-
// target: { value: `${immutable_file_number}` },
40-
target: { value: immutable_file_number },
41-
});
29+
it.each([0, 123, 67_782, maxImmutable])(
30+
"Immutable below or equal to max allowed: %d",
31+
(immutable_file_number) => {
32+
const { input } = setup(maxImmutable);
33+
fireEvent.change(input, {
34+
target: { value: immutable_file_number },
35+
});
4236

43-
expect(input.checkValidity()).toBeTruthy();
44-
expect(input.value).toBe(`${immutable_file_number}`);
45-
});
37+
expect(input.checkValidity()).toBeTruthy();
38+
expect(input.value).toBe(`${immutable_file_number}`);
39+
},
40+
);
4641

47-
test.prop({
48-
immutable_file_number: fc.oneof(fc.integer({ max: -1 }), fc.integer({ min: maxImmutable + 1 })),
49-
})("Immutable above max or below 0 is invalid", ({ immutable_file_number }) => {
50-
const { input } = setup(maxImmutable);
51-
fireEvent.change(input, {
52-
target: { value: immutable_file_number },
53-
});
42+
it.each([-4328, -1, maxImmutable + 1, 528_432])(
43+
"Immutable above max or below 0 is invalid: %d",
44+
(immutable_file_number) => {
45+
const { input } = setup(maxImmutable);
46+
fireEvent.change(input, {
47+
target: { value: immutable_file_number },
48+
});
5449

55-
expect(input.checkValidity()).toBeFalsy();
56-
});
50+
expect(input.checkValidity()).toBeFalsy();
51+
},
52+
);
5753

58-
test.prop({
59-
immutable_file_number: fc.string({ minLength: 1 }).filter((s) => isNaN(parseInt(s))),
60-
})("Non-number is invalid", ({ immutable_file_number }) => {
54+
it.each(["@124", "⚠️", "text"])("Non-number is invalid: %s", (immutable_file_number) => {
6155
const { input } = setup({ maxImmutable });
6256
fireEvent.change(input, {
6357
target: { value: immutable_file_number },
@@ -66,9 +60,7 @@ describe("DownloadImmutableFormInput", () => {
6660
expect(input.checkValidity()).toBeFalsy();
6761
});
6862

69-
test.prop({
70-
immutable_file_number: fc.float({ noInteger: true }),
71-
})("Float is invalid", ({ immutable_file_number }) => {
63+
it.each([0.1, 1.432, 67_782.32])("Float is invalid: %f", ({ immutable_file_number }) => {
7264
const { input } = setup({ maxImmutable });
7365
fireEvent.change(input, {
7466
target: { value: immutable_file_number },

mithril-explorer/package-lock.json

Lines changed: 0 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-explorer/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@
2727
"react-redux": "^9.2.0"
2828
},
2929
"devDependencies": {
30-
"@fast-check/jest": "^2.0.3",
3130
"@testing-library/jest-dom": "^6.6.3",
3231
"@testing-library/react": "^16.2.0",
3332
"eslint": "^9.18.0",
3433
"eslint-config-next": "^15.1.5",
3534
"fantasticon": "^3.0.0",
36-
"fast-check": "^3.23.2",
3735
"jest": "^29.7.0",
3836
"jest-environment-jsdom": "^29.7.0",
3937
"next-router-mock": "^0.9.13",

0 commit comments

Comments
 (0)