@itwin/core-backend
Version:
iTwin.js backend components
55 lines • 2.38 kB
JavaScript
import * as sinon from "sinon";
import { expect } from "chai";
import { IpcHandler, IpcHost } from "../IpcHost";
class MockIpcHandler extends IpcHandler {
get channelName() { return "mock-channel"; }
mockMethod() {
return "mock-value";
}
#privateFunction() { }
}
describe("IpcHost", () => {
let socket;
beforeEach(async () => {
socket = {
send: sinon.stub(),
addListener: sinon.stub(),
removeListener: sinon.stub(),
handle: sinon.stub(),
};
await IpcHost.startup({ ipcHost: { socket } });
});
describe("IpcHandler", () => {
it("should call public methods", async () => {
MockIpcHandler.register();
const handleCall = socket.handle.getCalls().find((call) => call.args[0] === "itwin.mock-channel");
expect(handleCall).to.not.be.undefined;
const handler = handleCall.args[1];
expect(typeof handler).to.equal("function");
const ipcReturn = await handler(undefined, "mockMethod");
expect(ipcReturn.result).to.equal("mock-value");
expect(ipcReturn.error).to.be.undefined;
});
it("should not call private methods", async () => {
MockIpcHandler.register();
const handleCall = socket.handle.getCalls().find((call) => call.args[0] === "itwin.mock-channel");
expect(handleCall).to.not.be.undefined;
const handler = handleCall.args[1];
expect(typeof handler).to.equal("function");
const ipcReturn = await handler(undefined, "#privateFunction");
expect(ipcReturn.result).to.be.undefined;
expect(ipcReturn.error).to.not.be.undefined;
});
it("should not call methods inherited from Object", async () => {
MockIpcHandler.register();
const handleCall = socket.handle.getCalls().find((call) => call.args[0] === "itwin.mock-channel");
expect(handleCall).to.not.be.undefined;
const handler = handleCall.args[1];
expect(typeof handler).to.equal("function");
const ipcReturn = await handler(undefined, "toString");
expect(ipcReturn.result).to.be.undefined;
expect(ipcReturn.error).to.not.be.undefined;
});
});
});
//# sourceMappingURL=IpcHost.test.js.map