From e3ef7c192ab1c43f3787bcc2715e208f0b659424 Mon Sep 17 00:00:00 2001 From: Tessa Walsh Date: Wed, 5 Jul 2023 16:40:44 -0400 Subject: [PATCH] Mock promisify --- tests/storage.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/storage.test.js b/tests/storage.test.js index fb093c2d..353bd9f9 100644 --- a/tests/storage.test.js +++ b/tests/storage.test.js @@ -1,5 +1,5 @@ import { jest } from "@jest/globals"; -import child_process from "child_process"; +import util from "util"; import { calculatePercentageUsed, checkDiskUtilization } from "../util/storage.js"; const mockDfOutput = `Filesystem 1K-blocks Used Available Use% Mounted on @@ -17,7 +17,11 @@ test("ensure calculatePercentageUsed returns expected values", () => { expect(calculatePercentageUsed(0, 5)).toEqual(0); }); -jest.mock("child_process"); +jest.mock("util", () => ({ + promisify: jest.fn(() => { + return jest.fn().mockResolvedValue({ stdout: mockDfOutput }); + }) +})); test("verify end-to-end disk utilization check works as expected with mock df return", async () => { const params = { @@ -26,8 +30,6 @@ test("verify end-to-end disk utilization check works as expected with mock df re generateWACZ: true }; - child_process.exec.mockImplementation((command, callback) => callback(null, {stdout: mockDfOutput})); - const returnValue = await checkDiskUtilization(params, 7500000); expect(returnValue).toEqual({ stop: false,