Skip to content

Commit

Permalink
test: add unit tests for the Messages class (#9)
Browse files Browse the repository at this point in the history
* test: add test for the Messages class

* 1.3.0
  • Loading branch information
sapachev authored Feb 6, 2023
1 parent d5dc979 commit 5cefa64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "error-pages",
"version": "1.2.1",
"version": "1.3.0",
"description": "Lightweight tool to create static HTTP Error Pages in minimalistic adaptive and accessible design with customization and localization support",
"main": "index.ts",
"scripts": {
Expand Down
32 changes: 32 additions & 0 deletions test/Messages.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { assert } from "chai";
import { Messages } from "../lib/classes/Messages";

describe("class Messages", () => {
const key = "test";
const vars = {
[key]: "TEST",
};
const noVarsMsg = "no vars";
const withVarsMsg = "with var";

const methods = new Map<string, string>([
["error", "ERROR: "],
["info", "INFO: "],
["list", " • "],
["skip", " SKIP: "],
["text", ""],
["warn", "WARN: "],
]);

methods.forEach((prefix: string, method: string) => {
describe(`${method}()`, () => {
it("should be rendered to formatted string without variables", () => {
assert.equal(Messages[method](noVarsMsg), `${prefix}${noVarsMsg}`);
});

it("should be rendered to formatted string with variables", () => {
assert.equal(Messages[method](`${withVarsMsg} {{ ${key} }}`, vars), `${prefix}${withVarsMsg} ${vars[key]}`);
});
});
});
});

0 comments on commit 5cefa64

Please sign in to comment.