import { getStatus } from "./callHook"; import { IElementParams, IElementState } from "../types"; describe("callHook tests", () => { describe("getStatus tests", () => { const func1 = jest.fn(); const params: IElementParams = { func: func1, args: ["arg1", "arg2"], }; const tests: Array<{ name: string; currentCallNumber: number; stack: IElementState["stack"]; currentCall: IElementState["currentCall"]; params: IElementParams; result: ReturnType; }> = [ { name: "when currentCallNumber is 0 and stack is empty, should restart", currentCallNumber: 0, stack: [], currentCall: undefined, params, result: "restart", }, { name: "when currentCallNumber is 1 and stack.length = 1 and there is not currentCall should restart", currentCallNumber: 1, stack: [{ args: [], func: jest.fn() }], currentCall: undefined, params, result: "restart", }, { name: "when currentCallNumber is 1 and stack.length is 1 and there is currentCall, should be none", currentCallNumber: 1, stack: [{ args: [], func: jest.fn() }], currentCall: { elementId: 15 }, params, result: "none", }, { name: "when currentCallNumber greater than stack.length and there is currentCall, should be none", currentCallNumber: 2, stack: [{ args: [], func: jest.fn() }], currentCall: { elementId: 1 }, params, result: "none", }, { name: "when currentCallNumber greater than stack.length and there is not currentCall, should be none", currentCallNumber: 2, stack: [{ args: [], func: jest.fn() }], currentCall: undefined, params, result: "none", }, ]; tests.forEach((test) => { it(name, () => { expect(getStatus(test.currentCallNumber, test.stack, test.params, test.currentCall)).toBe(test.result); }); }); }); });