Skip to content

Commit 430b7c2

Browse files
authored
Added toBeDefined & toBeUndefined matchers to test API (#9207)
## Summary Added toBeDefined & toBeUndefined matchers to test API ## Test plan Build app, add a test to the test suite and use .toBeDefined() in your tests
1 parent ad5f5e7 commit 430b7c2

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

apps/common-app/src/apps/reanimated/examples/RuntimeTests/ReJest/matchers/Matchers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import {
55
toBeCalledJSMatcher,
66
toBeCalledMatcher,
77
toBeCalledUIMatcher,
8+
toBeDefined,
89
toBeMatcher,
910
toBeNullableMatcher,
11+
toBeUndefined,
1012
toBeWithinRangeMatcher,
1113
toThrowMatcher,
1214
} from './rawMatchers';
@@ -44,7 +46,9 @@ export class Matchers {
4446
}
4547

4648
public toBe = this.decorateMatcher(toBeMatcher);
49+
public toBeDefined = this.decorateMatcher(toBeDefined);
4750
public toBeNullable = this.decorateMatcher(toBeNullableMatcher);
51+
public toBeUndefined = this.decorateMatcher(toBeUndefined);
4852
public toBeWithinRange = this.decorateMatcher(toBeWithinRangeMatcher);
4953
public toThrow = this.decorateAsyncMatcher(toThrowMatcher);
5054
public toBeCalled = this.decorateMatcher(toBeCalledMatcher);

apps/common-app/src/apps/reanimated/examples/RuntimeTests/ReJest/matchers/rawMatchers.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ export const toBeMatcher: Matcher<ToBeArgs> = (currentValue, negation, expectedV
5555
};
5656
};
5757

58+
export const toBeDefined: Matcher<ToBeNullArgs> = (currentValue, negation) => {
59+
const coloredExpected = green('defined');
60+
const coloredReceived = red(currentValue);
61+
62+
return {
63+
pass: currentValue !== undefined,
64+
message: `Expected${negation ? ' NOT' : ''} ${coloredExpected} received ${coloredReceived}`,
65+
};
66+
};
67+
68+
export const toBeUndefined: Matcher<ToBeNullArgs> = (currentValue, negation) => {
69+
const coloredExpected = green('undefined');
70+
const coloredReceived = red(currentValue);
71+
72+
return {
73+
pass: currentValue === undefined,
74+
message: `Expected${negation ? ' NOT' : ''} ${coloredExpected} received ${coloredReceived}`,
75+
};
76+
};
77+
5878
export const toBeNullableMatcher: Matcher<ToBeNullArgs> = (currentValue, negation) => {
5979
const coloredExpected = green('nullable');
6080
const coloredReceived = red(currentValue);

0 commit comments

Comments
 (0)