NimitzDEV/nestjs-electron-ipc-transport

cannot test controller methods

Closed this issue · 2 comments

Hello, I got the error when trying to test controller methods with jest. It seems "electron_1.ipcMain" is undefined.
Is this my bug or this lib does not support jest? Could you please help me out? Thanks you.

Test suite failed to run

TypeError: Cannot read properties of undefined (reading 'handle')

  22 | 	) {}
  23 |
> 24 | 	@IpcInvoke("trade.placeOrder")
     | 	 ^
  25 | 	async placeOrder(params: PlaceOrderParam): Promise<HttpResponse<string>> {
  26 |
  27 | 		// const user = await this.userService.find(params.auth);

  at IpcInvoke (node_modules/nestjs-electron-ipc-transport/dist/libs/decorators/AsyncIPCMessage.js:14:24)
  at Object.<anonymous> (src/server/main/interfaces/tradescheduler/tradeSchedulerIpcService.ts:24:3)
  at Object.<anonymous> (src/server/__tests__/interfaces/tradescheduler/tradeSchedulerIpcService.test.ts:3:1)

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IpcInvoke = exports.IpcCall = void 0;
const common_1 = require("@nestjs/common");
const microservices_1 = require("@nestjs/microservices");
const electron_1 = require("electron");
const event_1 = require("../event");
function IpcCall(messageChannel) {
electron_1.ipcMain.on(messageChannel, (...args) => event_1.ipcMessageDispatcher.emit(messageChannel, ...args));
return common_1.applyDecorators(microservices_1.MessagePattern(messageChannel));
}
exports.IpcCall = IpcCall;
function IpcInvoke(messageChannel) {
electron_1.ipcMain.handle(messageChannel, (...args) => event_1.ipcMessageDispatcher.emit(messageChannel, ...args));
return common_1.applyDecorators(microservices_1.MessagePattern(messageChannel));
}
exports.IpcInvoke = IpcInvoke;

Please make sure you are injecting dependencies properly

Solved by mock electron "handle" function.