MCPcopy
hub / github.com/jestjs/jest / expect

Function expect

packages/expect/src/index.ts:105–157  ·  packages/expect/src/index.ts::expect
(actual: any, ...rest: Array<any>)

Source from the content-addressed store, hash-verified

103};
104
105export const expect: Expect = (actual: any, ...rest: Array<any>) => {
106 if (rest.length > 0) {
107 throw new Error(class="st">'Expect takes at most one argument.');
108 }
109
110 const allMatchers = getMatchers();
111 const expectation: any = {
112 not: {},
113 rejects: {not: {}},
114 resolves: {not: {}},
115 };
116
117 const err = new JestAssertionError();
118
119 for (const name of Object.keys(allMatchers)) {
120 const matcher = allMatchers[name];
121 const promiseMatcher = getPromiseMatcher(name, matcher) || matcher;
122 expectation[name] = makeThrowingMatcher(matcher, false, class="st">'', actual);
123 expectation.not[name] = makeThrowingMatcher(matcher, true, class="st">'', actual);
124
125 expectation.resolves[name] = makeResolveMatcher(
126 name,
127 promiseMatcher,
128 false,
129 actual,
130 err,
131 );
132 expectation.resolves.not[name] = makeResolveMatcher(
133 name,
134 promiseMatcher,
135 true,
136 actual,
137 err,
138 );
139
140 expectation.rejects[name] = makeRejectMatcher(
141 name,
142 promiseMatcher,
143 false,
144 actual,
145 err,
146 );
147 expectation.rejects.not[name] = makeRejectMatcher(
148 name,
149 promiseMatcher,
150 true,
151 actual,
152 err,
153 );
154 }
155
156 return expectation;
157};
158
159const getMessage = (message?: () => string) =>
160 (message && message()) ||

Callers 15

expect.test.tsFile · 0.90
tester1Function · 0.90
toBeWithinRangeFunction · 0.90
toHaveContextFunction · 0.90
customContextFunction · 0.90
customContextAndExpectedFunction · 0.90
hooksError.test.tsFile · 0.85

Calls 5

getMatchersFunction · 0.90
getPromiseMatcherFunction · 0.85
makeThrowingMatcherFunction · 0.85
makeResolveMatcherFunction · 0.85
makeRejectMatcherFunction · 0.85

Tested by 15

tester1Function · 0.72
toBeWithinRangeFunction · 0.72
toHaveContextFunction · 0.72
customContextFunction · 0.72
customContextAndExpectedFunction · 0.72
testPathArrayFunction · 0.68
matchErrorSnapshotFunction · 0.68
assertPatternFunction · 0.68
assertPatternFunction · 0.68
testDiffContextLinesFunction · 0.68
assertCallsToChildFunction · 0.68