You've already forked joplin
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:
@ -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.');
|
||||
|
Reference in New Issue
Block a user