forked from anuraghazra/github-readme-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add I18n class tests (anuraghazra#3188)
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'", | ||
); | ||
}); | ||
}); |