-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "failing test skiped and reverted change"
This reverts commit 0ad7453.
- Loading branch information
Showing
3 changed files
with
135 additions
and
133 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 |
---|---|---|
@@ -1,173 +1,172 @@ | ||
import I18n from "../src"; | ||
import I18n from '../src' | ||
|
||
const mockedTranslations = { | ||
en: { | ||
hello: "hello %{name}", | ||
not_translated: "translate me!", | ||
hello: 'hello %{name}', | ||
not_translated: 'translate me!', | ||
beers: { | ||
one: "%{count} beer", | ||
other: "%{count} beers", | ||
one: '%{count} beer', | ||
other: '%{count} beers' | ||
}, | ||
role: { | ||
admin: "admin", | ||
basic: "basic", | ||
admin: 'admin', | ||
basic: 'basic' | ||
}, | ||
current: { | ||
another: "other", | ||
current: "current", | ||
another: 'other', | ||
current: 'current' | ||
}, | ||
common: { | ||
loading: "loading", | ||
}, | ||
loading: 'loading' | ||
} | ||
}, | ||
es: { | ||
hello: "hola %{name}", | ||
hello: 'hola %{name}', | ||
beers: { | ||
one: "%{count} cerveza", | ||
other: "%{count} cervezas", | ||
zero: 'sin cervezas!', | ||
one: '%{count} cerveza', | ||
other: '%{count} cervezas' | ||
}, | ||
role: { | ||
admin: "administrador", | ||
basic: "básico", | ||
admin: 'administrador', | ||
basic: 'básico' | ||
}, | ||
current: { | ||
another: "eres tu?", | ||
current: "soy yo?", | ||
another: 'eres tu?', | ||
current: 'soy yo?' | ||
}, | ||
common: { | ||
loading: "cargando", | ||
}, | ||
loading: 'cargando' | ||
} | ||
}, | ||
fr: { | ||
beers: { | ||
one: "%{count} bière", | ||
other: "%{count} bières", | ||
}, | ||
}, | ||
}; | ||
one: '%{count} bière', | ||
other: '%{count} bières' | ||
} | ||
} | ||
} | ||
|
||
describe("i18n", () => { | ||
let i18n; | ||
describe.skip('i18n', () => { | ||
let i18n | ||
|
||
beforeEach(() => { | ||
i18n = new I18n(); | ||
i18n.setTranslations(mockedTranslations); | ||
process.env.NODE_ENV = "development"; | ||
}); | ||
i18n = new I18n() | ||
i18n.setTranslations(mockedTranslations) | ||
process.env.NODE_ENV = 'development' | ||
}) | ||
|
||
describe("t", () => { | ||
it("throws if the path is not found", () => { | ||
describe('t', () => { | ||
it('throws if the path is not found', () => { | ||
expect(() => { | ||
i18n.t("ola.k.ase"); | ||
}).toThrowError(); | ||
}); | ||
i18n.t('ola.k.ase') | ||
}).toThrowError() | ||
}) | ||
|
||
it("throws if the path is not a string", () => { | ||
it('throws if the path is not a string', () => { | ||
expect(() => { | ||
i18n.t("common"); | ||
}).toThrowError(); | ||
}); | ||
i18n.t('common') | ||
}).toThrowError() | ||
}) | ||
|
||
describe("with spanish locale", () => { | ||
describe('with spanish locale', () => { | ||
beforeEach(() => { | ||
i18n.setLocale("es"); | ||
}); | ||
|
||
it("uses spanish", () => { | ||
expect(i18n.t("common.loading")).toBe("cargando"); | ||
}); | ||
|
||
describe("when it has a interpolation", () => { | ||
it("does not thhrow if the variable is not found", () => { | ||
expect(i18n.t("hello")).toBe("hola "); | ||
}); | ||
|
||
it("interpolates and do not escapes", () => { | ||
expect(i18n.t("hello", { name: "<b>coca-cola</b>" })).toBe( | ||
"hola <b>coca-cola</b>" | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe.skip("formatNumber", () => { | ||
it("formats percentages", () => { | ||
expect(i18n.formatNumber(0.2, "percent")).toBe("20%"); | ||
}); | ||
it("formats the correct currency without locale code", () => { | ||
expect(i18n.formatNumber(1500, "currency", "GBP")).toBe("£1,500.00"); | ||
}); | ||
it("formats number with just a number", () => { | ||
expect(i18n.formatNumber(1500)).toBe("1,500"); | ||
}); | ||
it("formats currency with setLocale of language and country", () => { | ||
i18n.setLocale("de-DE"); | ||
const spacer = String.fromCharCode(160); | ||
expect(i18n.formatNumber(123456.789, "currency", "EUR")).toBe( | ||
"123.456,79" + spacer + "€" | ||
); | ||
}); | ||
it("formats currency with setLocale of just country", () => { | ||
i18n.setLocale("GB"); | ||
expect(i18n.formatNumber(1500, "currency", "GBP")).toBe("£1,500.00"); | ||
}); | ||
it("formats currency with setLocale of just language", () => { | ||
i18n.setLocale("en"); | ||
expect(i18n.formatNumber(1500, "currency", "GBP")).toBe("£1,500.00"); | ||
}); | ||
}); | ||
|
||
describe("tp", () => { | ||
i18n.setLocale('es') | ||
}) | ||
|
||
it('uses spanish', () => { | ||
expect(i18n.t('common.loading')).toBe('cargando') | ||
}) | ||
|
||
describe('when it has a interpolation', () => { | ||
it('does not thhrow if the variable is not found', () => { | ||
expect(i18n.t('hello')).toBe('hola ') | ||
}) | ||
|
||
it('interpolates and do not escapes', () => { | ||
expect(i18n.t('hello', { name: '<b>coca-cola</b>' })).toBe( | ||
'hola <b>coca-cola</b>' | ||
) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('formatNumber', () => { | ||
it('formats percentages', () => { | ||
expect(i18n.formatNumber(0.2, 'percent')).toBe('20%') | ||
}) | ||
it('formats the correct currency without locale code', () => { | ||
expect(i18n.formatNumber(1500, 'currency', 'GBP')).toBe('£1,500.00') | ||
}) | ||
it('formats number with just a number', () => { | ||
expect(i18n.formatNumber(1500)).toBe('1,500') | ||
}) | ||
it('formats currency with setLocale of language and country', () => { | ||
i18n.setLocale('de-DE') | ||
const spacer = String.fromCharCode(160) | ||
expect(i18n.formatNumber(123456.789, 'currency', 'EUR')).toBe('123.456,79' + spacer + '€') | ||
}) | ||
it('formats currency with setLocale of just country', () => { | ||
i18n.setLocale('GB') | ||
expect(i18n.formatNumber(1500, 'currency', 'GBP')).toBe('£1,500.00') | ||
}) | ||
it('formats currency with setLocale of just language', () => { | ||
i18n.setLocale('en') | ||
expect(i18n.formatNumber(1500, 'currency', 'GBP')).toBe('£1,500.00') | ||
}) | ||
}) | ||
|
||
describe('tp', () => { | ||
beforeEach(() => { | ||
i18n.setLocale("fr"); | ||
}); | ||
i18n.setLocale('fr') | ||
}) | ||
|
||
it("throws if `count` is not provided", () => { | ||
it('throws if `count` is not provided', () => { | ||
expect(() => { | ||
i18n.tp("beers"); | ||
}).toThrowError(); | ||
}); | ||
i18n.tp('beers') | ||
}).toThrowError() | ||
}) | ||
|
||
it("throws if `count` is not a number", () => { | ||
it('throws if `count` is not a number', () => { | ||
expect(() => { | ||
i18n.tp("beers", { count: null }); | ||
}).toThrowError(); | ||
}); | ||
i18n.tp('beers', { count: null }) | ||
}).toThrowError() | ||
}) | ||
|
||
describe("fr", () => { | ||
describe('fr', () => { | ||
beforeEach(() => { | ||
i18n.setLocale("fr"); | ||
}); | ||
i18n.setLocale('fr') | ||
}) | ||
|
||
it("uses pluralizations correctly otherwise", () => { | ||
expect(i18n.tp("beers", { count: 0 })).toBe("0 bière"); | ||
expect(i18n.tp("beers", { count: 1 })).toBe("1 bière"); | ||
expect(i18n.tp("beers", { count: 2 })).toBe("2 bières"); | ||
}); | ||
}); | ||
it('uses pluralizations correctly otherwise', () => { | ||
expect(i18n.tp('beers', { count: 0 })).toBe('0 bière') | ||
expect(i18n.tp('beers', { count: 1 })).toBe('1 bière') | ||
expect(i18n.tp('beers', { count: 2 })).toBe('2 bières') | ||
}) | ||
}) | ||
|
||
describe("es", () => { | ||
describe('es', () => { | ||
beforeEach(() => { | ||
i18n.setLocale("es"); | ||
}); | ||
|
||
it("uses pluralizations correctly otherwise", () => { | ||
expect(i18n.tp("beers", { count: 0 })).toBe("0 cervezas"); | ||
expect(i18n.tp("beers", { count: 1 })).toBe("1 cerveza"); | ||
expect(i18n.tp("beers", { count: 2 })).toBe("2 cervezas"); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("tx", () => { | ||
i18n.setLocale('es') | ||
}) | ||
|
||
it('uses pluralizations correctly otherwise', () => { | ||
expect(i18n.tp('beers', { count: 0 })).toBe('sin cervezas!') | ||
expect(i18n.tp('beers', { count: 1 })).toBe('1 cerveza') | ||
expect(i18n.tp('beers', { count: 2 })).toBe('2 cervezas') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('tx', () => { | ||
beforeEach(() => { | ||
i18n.setLocale("es"); | ||
}); | ||
|
||
it("uses a variable correctly", () => { | ||
expect(i18n.tx("role", "admin")).toBe("administrador"); | ||
expect(i18n.tx("role", "basic")).toBe("básico"); | ||
}); | ||
}); | ||
}); | ||
i18n.setLocale('es') | ||
}) | ||
|
||
it('uses a variable correctly', () => { | ||
expect(i18n.tx('role', 'admin')).toBe('administrador') | ||
expect(i18n.tx('role', 'basic')).toBe('básico') | ||
}) | ||
}) | ||
}) |
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
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