// The shared fake `t` (#389): its mark is the convention every assertion reads. import { describe, it, expect } from "vitest"; import { i18nMock, markedT } from "./i18nMock"; describe("markedT", () => { it("marks a key without options", () => { expect(markedT("license.removeKey.confirmValid")).toBe("t(license.removeKey.confirmValid)"); }); it("marks a key with its options, in their order", () => { expect(markedT("budget.count", { count: 2, name: "x" })).toBe("t(budget.count[count=2,name=x])"); }); it("never returns the bare key", () => { expect(markedT("a.b")).not.toBe("a.b"); }); }); describe("i18nMock", () => { it("hands out the marked t and the French language by default", () => { const { t, i18n } = i18nMock().useTranslation(); expect(t("a.b", { n: 1 })).toBe("t(a.b[n=1])"); expect(i18n.language).toBe("fr"); }); it("reads a language function at each access", () => { let language = "fr"; const { i18n } = i18nMock({ language: () => language }).useTranslation(); expect(i18n.language).toBe("fr"); language = "en"; expect(i18n.language).toBe("en"); }); it("returns the fixture value for a fixture key, the mark for any other", () => { const value = [{ id: "x" }]; const { t } = i18nMock({ fixture: { "docs.a.subsections": value } }).useTranslation(); expect(t("docs.a.subsections", { returnObjects: true })).toBe(value); expect(t("docs.b.subsections", { returnObjects: true })).toBe("t(docs.b.subsections[returnObjects=true])"); expect(t("toString")).toBe("t(toString)"); }); });