From f0ec6840b454b938cdfe09323d7f3c6d5a4e9fa9 Mon Sep 17 00:00:00 2001 From: Michael Mok Date: Mon, 4 Apr 2022 09:51:15 +0200 Subject: [PATCH] test: add test for initialized instance --- test/client/socket-helper.test.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/client/socket-helper.test.js b/test/client/socket-helper.test.js index 4951949d6c..17077de0a8 100644 --- a/test/client/socket-helper.test.js +++ b/test/client/socket-helper.test.js @@ -5,7 +5,7 @@ "use strict"; describe("socket", () => { - afterEach(() => { + beforeEach(() => { jest.resetAllMocks(); jest.resetModules(); }); @@ -77,4 +77,19 @@ describe("socket", () => { expect(mockClientInstance.onMessage.mock.calls).toMatchSnapshot(); expect(mockHandler.mock.calls).toMatchSnapshot(); }); + + it("should export initialized client", () => { + const socket = require("../../client/socket").default; + + const nonInitializedInstance = require("../../client/socket").client; + expect(nonInitializedInstance).toBe(null); + + socket("my.url", {}); + + const initializedInstance = require("../../client/socket").client; + expect(initializedInstance).not.toBe(null); + expect(typeof initializedInstance.onClose).toBe("function"); + expect(typeof initializedInstance.onMessage).toBe("function"); + expect(typeof initializedInstance.onOpen).toBe("function"); + }); });