diff --git a/src/types/utils/AsMutable.ts b/src/types/utils/AsMutable.ts new file mode 100644 index 000000000000..57c49058cd14 --- /dev/null +++ b/src/types/utils/AsMutable.ts @@ -0,0 +1,5 @@ +import type {Writable} from 'type-fest'; + +const asMutable = (value: T): Writable => value as Writable; + +export default asMutable; diff --git a/tests/utils/PusherHelper.js b/tests/utils/PusherHelper.ts similarity index 68% rename from tests/utils/PusherHelper.js rename to tests/utils/PusherHelper.ts index 3d0ce1404a91..1d6833e43504 100644 --- a/tests/utils/PusherHelper.js +++ b/tests/utils/PusherHelper.ts @@ -1,7 +1,9 @@ -import CONFIG from '../../src/CONFIG'; -import CONST from '../../src/CONST'; -import * as Pusher from '../../src/libs/Pusher/pusher'; -import PusherConnectionManager from '../../src/libs/PusherConnectionManager'; +import type {OnyxUpdate} from 'react-native-onyx'; +import CONFIG from '@src/CONFIG'; +import CONST from '@src/CONST'; +import * as Pusher from '@src/libs/Pusher/pusher'; +import PusherConnectionManager from '@src/libs/PusherConnectionManager'; +import asMutable from '@src/types/utils/AsMutable'; const CHANNEL_NAME = `${CONST.PUSHER.PRIVATE_USER_CHANNEL_PREFIX}1${CONFIG.PUSHER.SUFFIX}`; @@ -10,8 +12,8 @@ function setup() { // channel already in a subscribed state. These methods are normally used to prevent // duplicated subscriptions, but we don't need them for this test so forcing them to // return false will make the testing less complex. - Pusher.isSubscribed = jest.fn().mockReturnValue(false); - Pusher.isAlreadySubscribing = jest.fn().mockReturnValue(false); + asMutable(Pusher).isSubscribed = jest.fn().mockReturnValue(false); + asMutable(Pusher).isAlreadySubscribing = jest.fn().mockReturnValue(false); // Connect to Pusher PusherConnectionManager.init(); @@ -22,12 +24,9 @@ function setup() { }); } -/** - * @param {Array} args - */ -function emitOnyxUpdate(args) { +function emitOnyxUpdate(args: OnyxUpdate[]) { const channel = Pusher.getChannel(CHANNEL_NAME); - channel.emit(Pusher.TYPE.MULTIPLE_EVENTS, [ + channel?.emit(Pusher.TYPE.MULTIPLE_EVENTS, [ { eventType: Pusher.TYPE.MULTIPLE_EVENT_TYPE.ONYX_API_UPDATE, data: args,