Skip to content

Commit

Permalink
add displayBanner() test
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhyan committed Nov 14, 2024
1 parent 014ded0 commit ac0660b
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/utils.test.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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();
});
});

0 comments on commit ac0660b

Please sign in to comment.