forked from netlify/netlify-identity-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
48 lines (40 loc) · 1.64 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
describe("translations", () => {
beforeEach(() => {
jest.resetModules();
});
it("should return translation for default locale", () => {
const { getTranslation } = require("./");
expect(getTranslation("log_in")).toEqual("Log in");
});
it("should return translation for 'en' locale", () => {
const { getTranslation } = require("./");
expect(getTranslation("log_in", "en")).toEqual("Log in");
});
it("should return translation for 'fr' locale", () => {
const { getTranslation } = require("./");
expect(getTranslation("log_in", "fr")).toEqual("Connexion");
});
it("should return translation for 'hu' locale", () => {
const { getTranslation } = require("./");
expect(getTranslation("log_in", "hu")).toEqual("Bejelentkezés");
});
it("should return translation for 'es' locale", () => {
const { getTranslation } = require("./");
expect(getTranslation("log_in", "es")).toEqual("Iniciar sesión");
});
it("should return key for non existing translation", () => {
const { getTranslation } = require("./");
expect(getTranslation("unknown_key")).toEqual("unknown_key");
});
it("should default to 'en' on missing key", () => {
jest.mock("./en.json", () => ({ log_in: "Log in" }));
jest.mock("./fr.json", () => ({}));
jest.mock("./hu.json", () => ({}));
jest.mock("./es.json", () => ({}));
const { getTranslation } = require("./");
expect(getTranslation("log_in")).toEqual("Log in");
expect(getTranslation("log_in", "fr")).toEqual("Log in");
expect(getTranslation("log_in", "hu")).toEqual("Log in");
expect(getTranslation("log_in", "es")).toEqual("Log in");
});
});