Skip to content

Commit d775bc9

Browse files
committed
loadCoreTranslationsFallback unit test
1 parent 8552876 commit d775bc9

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/unit/classes/translator_spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,38 @@ describe("Translator", function() {
241241
};
242242
});
243243
});
244+
245+
describe("loadCoreTranslationsFallback", function() {
246+
it("should load core translations fallback", function(done) {
247+
const dom = new JSDOM(`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
248+
<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
249+
resources: "usable" });
250+
dom.window.onload = function() {
251+
const {Translator} = dom.window;
252+
Translator.loadCoreTranslationsFallback();
253+
254+
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
255+
setTimeout(function() {
256+
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
257+
done();
258+
}, 500);
259+
};
260+
});
261+
262+
it("should load core fallback if language cannot be found", function(done) {
263+
const dom = new JSDOM(`<script>var translations = {}; var Log = {log: function(){}};</script>\
264+
<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
265+
resources: "usable" });
266+
dom.window.onload = function() {
267+
const {Translator} = dom.window;
268+
Translator.loadCoreTranslations();
269+
270+
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
271+
setTimeout(function() {
272+
expect(Translator.coreTranslationsFallback).to.be.deep.equal({});
273+
done();
274+
}, 500);
275+
};
276+
});
277+
});
244278
});

0 commit comments

Comments
 (0)