From ac0660be1427dba1715f52233c19e6c51c255934 Mon Sep 17 00:00:00 2001 From: vinhyan Date: Wed, 13 Nov 2024 19:06:40 -0500 Subject: [PATCH] add displayBanner() test --- src/utils.test.js | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/src/utils.test.js b/src/utils.test.js index 46aac1f..7b233f1 100644 --- a/src/utils.test.js +++ b/src/utils.test.js @@ -1,7 +1,5 @@ /* global global */ import { describe, expect, jest, test } from "@jest/globals"; -// import { createRequire } from "module"; -// const require = createRequire(import.meta.url); let homeDir = "/home/user"; @@ -69,9 +67,8 @@ const { capFirstLetter, getIso639LanguageCode, displayTranslatedContents, + displayBanner, } = await import("./utils.js"); -// const ISO6391 = require("iso-639-1"); -// const { iso6393 } = await import("iso-639-3"); describe("getConfig() tests", () => { const tomlFilePath = "/home/user/.barrierless.toml"; @@ -148,21 +145,21 @@ describe("getIso639LanguageCode() tests", () => { const originalConsoleLogFn = global.console.log; -describe("displayTranslatedContents() tests", () => { - let logOutput = null; +let logOutput = null; - function testLogFn(...args) { - logOutput = logOutput || []; - args.forEach((arg) => logOutput.push(arg)); - } +function testLogFn(...args) { + logOutput = logOutput || []; + args.forEach((arg) => logOutput.push(arg)); +} - function finalize(output) { - if (output && Array.isArray(output)) { - return output.join(""); - } - return output; +function finalize(output) { + if (output && Array.isArray(output)) { + return output.join(""); } + return output; +} +describe("displayTranslatedContents() tests", () => { beforeEach(() => { global.console.log = testLogFn; logOutput = null; @@ -185,3 +182,20 @@ describe("displayTranslatedContents() tests", () => { expect(finalize(logOutput)).toContain(expectedOutput); }); }); + +describe("displayBanner() tests", () => { + let consoleSpy; + + beforeEach(() => { + consoleSpy = jest.spyOn(global.console, "log"); + }); + + afterEach(() => { + consoleSpy.mockRestore(); + }); + + test("display banner", () => { + displayBanner(); + expect(consoleSpy).toHaveBeenCalled(); + }); +});