You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Mobile: Show loading indicator while loading search results (#11104)
This commit is contained in:
@ -1092,16 +1092,32 @@ export const mockMobilePlatform = (platform: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const runWithFakeTimers = (callback: ()=> Promise<void>) => {
|
||||
export const runWithFakeTimers = async (callback: ()=> Promise<void>) => {
|
||||
if (typeof jest === 'undefined') {
|
||||
throw new Error('Fake timers are only supported in jest.');
|
||||
}
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
// The shim.setTimeout and similar functions need to be changed to
|
||||
// use fake timers.
|
||||
const originalSetTimeout = shim.setTimeout;
|
||||
const originalSetInterval = shim.setInterval;
|
||||
const originalClearTimeout = shim.clearTimeout;
|
||||
const originalClearInterval = shim.clearInterval;
|
||||
shim.setTimeout = setTimeout;
|
||||
shim.setInterval = setInterval;
|
||||
shim.clearInterval = clearInterval;
|
||||
shim.clearTimeout = clearTimeout;
|
||||
|
||||
try {
|
||||
return callback();
|
||||
return await callback();
|
||||
} finally {
|
||||
jest.runOnlyPendingTimers();
|
||||
shim.setTimeout = originalSetTimeout;
|
||||
shim.setInterval = originalSetInterval;
|
||||
shim.clearTimeout = originalClearTimeout;
|
||||
shim.clearInterval = originalClearInterval;
|
||||
jest.useRealTimers();
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user