From 438ffb5ee87157782f9a2344712d8dd0e3b407cc Mon Sep 17 00:00:00 2001 From: Alexandr Garbuzov Date: Fri, 1 Sep 2023 09:36:23 +0300 Subject: [PATCH] tests: add I18n class tests (#3188) --- tests/i18n.test.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/i18n.test.js diff --git a/tests/i18n.test.js b/tests/i18n.test.js new file mode 100644 index 00000000..04666825 --- /dev/null +++ b/tests/i18n.test.js @@ -0,0 +1,33 @@ +import { expect, it, describe } from "@jest/globals"; +import { I18n } from "../src/common/I18n.js"; +import { statCardLocales } from "../src/translations.js"; + +describe("I18n", () => { + it("should return translated string", () => { + const i18n = new I18n({ + locale: "en", + translations: statCardLocales({ name: "Anurag Hazra", apostrophe: "s" }), + }); + expect(i18n.t("statcard.title")).toBe("Anurag Hazra's GitHub Stats"); + }); + + it("should throw error if translation string not found", () => { + const i18n = new I18n({ + locale: "en", + translations: statCardLocales({ name: "Anurag Hazra", apostrophe: "s" }), + }); + expect(() => i18n.t("statcard.title1")).toThrow( + "statcard.title1 Translation string not found", + ); + }); + + it("should throw error if translation not found for locale", () => { + const i18n = new I18n({ + locale: "asdf", + translations: statCardLocales({ name: "Anurag Hazra", apostrophe: "s" }), + }); + expect(() => i18n.t("statcard.title")).toThrow( + "'statcard.title' translation not found for locale 'asdf'", + ); + }); +});