I'm currently working on simulating the output of the sendToDevice
function from the Firebase library, but I'm facing a challenge with the return value of MessagingDevicesResponse
(refer to HERE in the code snippet below)
import MessagingDevicesResponse = admin.messaging.MessagingDevicesResponse;
const fnMock = (registrationToken, payload) => Promise.resolve<MessagingDevicesResponse>(/* Placeholder for response value */)
jest.spyOn(admin.messaging(), 'sendToDevice').mockImplementation(fnMock)
If I attempt something like this:
Promise.resolve<MessagingDevicesResponse>({ canonicalRegistrationTokenCount: 0 })
I encounter the error:
Argument of type '{ canonicalRegistrationTokenCount: number; }' is not assignable to parameter of type 'MessagingDevicesResponse | PromiseLike<MessagingDevicesResponse>'.
Type '{ canonicalRegistrationTokenCount: number; }' is missing the following properties from type 'MessagingDevicesResponse': failureCount, multicastId, results, successCountts(2345)
Another attempt:
Promise.resolve<MessagingDevicesResponse>(new MessagingDevicesResponse())
Results in:
'MessagingDevicesResponse' only refers to a type, but is being used as a value here.ts(2693)