MCPcopy
hub / github.com/callstack/react-native-testing-library / checkExpectation

Function checkExpectation

src/wait-for.ts:155–189  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153 }
154
155 function checkExpectation() {
156 /* istanbul ignore next */
157 if (promiseStatus === 'pending') {
158 return;
159 }
160
161 try {
162 const result = expectation();
163
164 // @ts-expect-error result can be a promise
165 if (typeof result?.then === 'function') {
166 const promiseResult: Promise<T> = result as unknown as Promise<T>;
167 promiseStatus = 'pending';
168 // eslint-disable-next-line promise/catch-or-return, promise/prefer-await-to-then
169 promiseResult.then(
170 (resolvedValue) => {
171 promiseStatus = 'resolved';
172 onDone({ type: 'result', result: resolvedValue });
173 return;
174 },
175 (rejectedValue) => {
176 promiseStatus = 'rejected';
177 lastError = rejectedValue;
178 return;
179 },
180 );
181 } else {
182 onDone({ type: 'result', result: result });
183 }
184 // If `callback` throws, wait for the next mutation, interval, or timeout.
185 } catch (error) {
186 // Save the most recent callback error to reject the promise with it in the event of a timeout
187 lastError = error;
188 }
189 }
190
191 function handleTimeout() {
192 let error: Error;

Callers 2

waitForInternalFunction · 0.85
checkRealTimersCallbackFunction · 0.85

Calls 1

onDoneFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…