1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-13 00:10:37 +02:00

Chore: Mobile: Improve note screen tests and fix CI warning (#11126)

This commit is contained in:
Henry Heino
2024-09-27 07:23:02 -07:00
committed by GitHub
parent 90640e590e
commit 5935c9c147
8 changed files with 143 additions and 29 deletions

View File

@ -1092,6 +1092,34 @@ export const mockMobilePlatform = (platform: string) => {
};
};
// Waits for callback to not throw. Similar to react-native-testing-library's waitFor, but works better
// with Joplin's mix of real and fake Jest timers.
const realSetTimeout = setTimeout;
export const waitFor = async (callback: ()=> Promise<void>) => {
const timeout = 10_000;
const startTime = performance.now();
let passed = false;
let lastError: Error|null = null;
while (!passed && performance.now() - startTime < timeout) {
try {
await callback();
passed = true;
lastError = null;
} catch (error) {
lastError = error;
await new Promise<void>(resolve => {
realSetTimeout(() => resolve(), 10);
});
}
}
if (lastError) {
throw lastError;
}
};
export const runWithFakeTimers = async (callback: ()=> Promise<void>) => {
if (typeof jest === 'undefined') {
throw new Error('Fake timers are only supported in jest.');