Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/types/utils/AsMutable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {Writable} from 'type-fest';

const asMutable = <T>(value: T): Writable<T> => value as Writable<T>;

export default asMutable;
21 changes: 10 additions & 11 deletions tests/utils/PusherHelper.js → tests/utils/PusherHelper.ts
Original file line number Diff line number Diff line change
@@ -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}`;

Expand All @@ -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();
Expand All @@ -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,
Expand Down