Skip to content

Commit 55de237

Browse files
committed
test(expectExtensions): support equality-check for objects
1 parent d1b448c commit 55de237

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

package-lock.json

+41-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
},
4848
"devDependencies": {
4949
"@babel/preset-typescript": "7.16.7",
50+
"@jest/expect-utils": "^28.0.0-alpha.0",
5051
"@types/jest": "27.4.1",
5152
"cpy-cli": "4.1.0",
5253
"jest": "27.5.1",

test/expectExtensions.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Maybe } from '@/src/maybe';
22
import { Result } from '@/src/result';
33
import { FunctionOfT, isDefined, isFunction } from '@/src/utilities';
4+
import { equals } from '@jest/expect-utils';
45

56
expect.extend({
67
toHaveNoValue<TValue>(received: Maybe<TValue>): MatchResponse {
@@ -25,7 +26,7 @@ expect.extend({
2526

2627
const value = received.getValueOrThrow();
2728

28-
return value === expectedValue
29+
return equals(value, expectedValue)
2930
? r(
3031
true,
3132
`expected [${received}] to have a value [${expectedValue}], but it has a value of [${value}]`
@@ -66,17 +67,15 @@ expect.extend({
6667

6768
const value = received.getValueOrThrow();
6869

69-
if (expectedValue === value) {
70-
return r(
71-
true,
72-
`expected [${received}] to be successful but not have value [${expectedValue}] but it did`
73-
);
74-
}
75-
76-
return r(
77-
false,
78-
`expected [${received}] to have value [${expectedValue}], but found value [${value}]`
79-
);
70+
return equals(expectedValue, value)
71+
? r(
72+
true,
73+
`expected [${received}] to be successful but not have value [${expectedValue}] but it did`
74+
)
75+
: r(
76+
false,
77+
`expected [${received}] to have value [${expectedValue}], but found value [${value}]`
78+
);
8079
},
8180
toFail<TValue, TError>(received: Result<TValue, TError>) {
8281
return received.isSuccess

0 commit comments

Comments
 (0)