Skip to content

Instantly share code, notes, and snippets.

@oharsta
Created May 17, 2017 20:04
Show Gist options
  • Save oharsta/a3c3452070c163d7911abbff023a9d73 to your computer and use it in GitHub Desktop.
Save oharsta/a3c3452070c163d7911abbff023a9d73 to your computer and use it in GitHub Desktop.
Verifying every I18n translation is present in all translations
import I18n from "i18n-js";
import en from "../locale/en";
import nl from "../locale/nl";
expect.extend({
toContainKey(translation, key) {
const pass = (translation[key] !== undefined);
return {
message: () => `Expected ${key} to be present in ${JSON.stringify(translation)}`,
pass: pass
};
},
});
test("All translations exists in EN and NL", () => {
const contains = (translation, translationToVerify) => {
Object.keys(translation).forEach(key => {
expect(translationToVerify).toContainKey(key);
const value = translation[key];
if (typeof value === "object") {
contains(value, translationToVerify[key])
}
});
};
contains(I18n.translations.en, I18n.translations.nl);
contains(I18n.translations.nl, I18n.translations.en);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment