mattermost-mobile/test/timer_helpers.ts
David Krauser c27f0eade2
[MM-62925] introduce websocket client-side ping (#8633)
This commit introduces new functionality on the client side to send PING messages over the websocket. If the server doesn't respond within PING_INTERVAL (currently 30 seconds), the connection is closed and re-created. This will allow us to find broken connections more quickly.
2025-03-11 11:48:09 -04:00

20 lines
698 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// Helper functions to handle Jest timer issues with async code
// These are needed because Jest's fake timers don't play well with Promise-based code.
// The combination of fake timers for time advancement + real timers for nextTick
// allows us to properly test async timing behavior.
export const enableFakeTimers = () => {
jest.useFakeTimers({doNotFake: ['nextTick']});
};
export const disableFakeTimers = () => {
jest.useRealTimers();
};
export const advanceTimers = async (ms: number) => {
jest.advanceTimersByTime(ms);
await new Promise(process.nextTick);
};