diff --git a/dist/amd/aurelia-i18n.d.ts b/dist/amd/aurelia-i18n.d.ts index 40206f46..352a0e6b 100644 --- a/dist/amd/aurelia-i18n.d.ts +++ b/dist/amd/aurelia-i18n.d.ts @@ -29,6 +29,7 @@ declare module 'aurelia-i18n' { /*eslint no-cond-assign: 0*/ export class I18N { globalVars: any; + i18nextDefered: any; constructor(ea: any, signaler: any); setup(options?: any): any; setLocale(locale: any): any; diff --git a/dist/amd/i18n.js b/dist/amd/i18n.js index d98c5325..5ab333f7 100644 --- a/dist/amd/i18n.js +++ b/dist/amd/i18n.js @@ -22,18 +22,27 @@ define(['exports', 'i18next'], function (exports, _i18next) { var I18N = exports.I18N = function () { function I18N(ea, signaler) { + var _this = this; + _classCallCheck(this, I18N); this.globalVars = {}; + this.i18nextDefered = { + resolve: null, + promise: null + }; this.i18next = _i18next2.default; this.ea = ea; this.Intl = window.Intl; this.signaler = signaler; + this.i18nextDefered.promise = new Promise(function (resolve) { + return _this.i18nextDefered.resolve = resolve; + }); } I18N.prototype.setup = function setup(options) { - var _this = this; + var _this2 = this; var defaultOptions = { compatibilityAPI: 'v1', @@ -44,25 +53,25 @@ define(['exports', 'i18next'], function (exports, _i18next) { debug: false }; - return new Promise(function (resolve) { - _i18next2.default.init(options || defaultOptions, function (err, t) { - if (_i18next2.default.options.attributes instanceof String) { - _i18next2.default.options.attributes = [_i18next2.default.options.attributes]; - } + _i18next2.default.init(options || defaultOptions, function (err, t) { + if (_i18next2.default.options.attributes instanceof String) { + _i18next2.default.options.attributes = [_i18next2.default.options.attributes]; + } - resolve(_this.i18next); - }); + _this2.i18nextDefered.resolve(_this2.i18next); }); + + return this.i18nextDefered.promise; }; I18N.prototype.setLocale = function setLocale(locale) { - var _this2 = this; + var _this3 = this; return new Promise(function (resolve) { - var oldLocale = _this2.getLocale(); - _this2.i18next.changeLanguage(locale, function (err, tr) { - _this2.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); - _this2.signaler.signal('aurelia-translation-signal'); + var oldLocale = _this3.getLocale(); + _this3.i18next.changeLanguage(locale, function (err, tr) { + _this3.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); + _this3.signaler.signal('aurelia-translation-signal'); resolve(tr); }); }); @@ -136,6 +145,14 @@ define(['exports', 'i18next'], function (exports, _i18next) { }; I18N.prototype.updateValue = function updateValue(node, value, params) { + var _this4 = this; + + this.i18nextDefered.promise.then(function () { + return _this4._updateValue(node, value, params); + }); + }; + + I18N.prototype._updateValue = function _updateValue(node, value, params) { if (value === null || value === undefined) { return; } diff --git a/dist/aurelia-i18n.d.ts b/dist/aurelia-i18n.d.ts index 40206f46..352a0e6b 100644 --- a/dist/aurelia-i18n.d.ts +++ b/dist/aurelia-i18n.d.ts @@ -29,6 +29,7 @@ declare module 'aurelia-i18n' { /*eslint no-cond-assign: 0*/ export class I18N { globalVars: any; + i18nextDefered: any; constructor(ea: any, signaler: any); setup(options?: any): any; setLocale(locale: any): any; diff --git a/dist/aurelia-i18n.js b/dist/aurelia-i18n.js index 0e159d24..e3323404 100644 --- a/dist/aurelia-i18n.js +++ b/dist/aurelia-i18n.js @@ -293,12 +293,17 @@ export class LazyOptional { export class I18N { globalVars = {}; + i18nextDefered = { + resolve: null, + promise: null + }; constructor(ea, signaler) { this.i18next = i18next; this.ea = ea; this.Intl = window.Intl; this.signaler = signaler; + this.i18nextDefered.promise = new Promise((resolve) => this.i18nextDefered.resolve = resolve); } setup(options?) { @@ -311,16 +316,16 @@ export class I18N { debug: false }; - return new Promise((resolve) => { - i18next.init(options || defaultOptions, (err, t) => { - //make sure attributes is an array in case a string was provided - if (i18next.options.attributes instanceof String) { - i18next.options.attributes = [i18next.options.attributes]; - } + i18next.init(options || defaultOptions, (err, t) => { + //make sure attributes is an array in case a string was provided + if (i18next.options.attributes instanceof String) { + i18next.options.attributes = [i18next.options.attributes]; + } - resolve(this.i18next); - }); + this.i18nextDefered.resolve(this.i18next); }); + + return this.i18nextDefered.promise; } setLocale(locale) { @@ -419,6 +424,10 @@ export class I18N { } updateValue(node, value, params) { + this.i18nextDefered.promise.then(() => this._updateValue(node, value, params)); + } + + _updateValue(node, value, params) { if (value === null || value === undefined) { return; } diff --git a/dist/commonjs/aurelia-i18n.d.ts b/dist/commonjs/aurelia-i18n.d.ts index 40206f46..352a0e6b 100644 --- a/dist/commonjs/aurelia-i18n.d.ts +++ b/dist/commonjs/aurelia-i18n.d.ts @@ -29,6 +29,7 @@ declare module 'aurelia-i18n' { /*eslint no-cond-assign: 0*/ export class I18N { globalVars: any; + i18nextDefered: any; constructor(ea: any, signaler: any); setup(options?: any): any; setLocale(locale: any): any; diff --git a/dist/commonjs/i18n.js b/dist/commonjs/i18n.js index 939eeac0..ba7901cd 100644 --- a/dist/commonjs/i18n.js +++ b/dist/commonjs/i18n.js @@ -15,18 +15,27 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var I18N = exports.I18N = function () { function I18N(ea, signaler) { + var _this = this; + _classCallCheck(this, I18N); this.globalVars = {}; + this.i18nextDefered = { + resolve: null, + promise: null + }; this.i18next = _i18next2.default; this.ea = ea; this.Intl = window.Intl; this.signaler = signaler; + this.i18nextDefered.promise = new Promise(function (resolve) { + return _this.i18nextDefered.resolve = resolve; + }); } I18N.prototype.setup = function setup(options) { - var _this = this; + var _this2 = this; var defaultOptions = { compatibilityAPI: 'v1', @@ -37,25 +46,25 @@ var I18N = exports.I18N = function () { debug: false }; - return new Promise(function (resolve) { - _i18next2.default.init(options || defaultOptions, function (err, t) { - if (_i18next2.default.options.attributes instanceof String) { - _i18next2.default.options.attributes = [_i18next2.default.options.attributes]; - } + _i18next2.default.init(options || defaultOptions, function (err, t) { + if (_i18next2.default.options.attributes instanceof String) { + _i18next2.default.options.attributes = [_i18next2.default.options.attributes]; + } - resolve(_this.i18next); - }); + _this2.i18nextDefered.resolve(_this2.i18next); }); + + return this.i18nextDefered.promise; }; I18N.prototype.setLocale = function setLocale(locale) { - var _this2 = this; + var _this3 = this; return new Promise(function (resolve) { - var oldLocale = _this2.getLocale(); - _this2.i18next.changeLanguage(locale, function (err, tr) { - _this2.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); - _this2.signaler.signal('aurelia-translation-signal'); + var oldLocale = _this3.getLocale(); + _this3.i18next.changeLanguage(locale, function (err, tr) { + _this3.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); + _this3.signaler.signal('aurelia-translation-signal'); resolve(tr); }); }); @@ -129,6 +138,14 @@ var I18N = exports.I18N = function () { }; I18N.prototype.updateValue = function updateValue(node, value, params) { + var _this4 = this; + + this.i18nextDefered.promise.then(function () { + return _this4._updateValue(node, value, params); + }); + }; + + I18N.prototype._updateValue = function _updateValue(node, value, params) { if (value === null || value === undefined) { return; } diff --git a/dist/es2015/aurelia-i18n.d.ts b/dist/es2015/aurelia-i18n.d.ts index 40206f46..352a0e6b 100644 --- a/dist/es2015/aurelia-i18n.d.ts +++ b/dist/es2015/aurelia-i18n.d.ts @@ -29,6 +29,7 @@ declare module 'aurelia-i18n' { /*eslint no-cond-assign: 0*/ export class I18N { globalVars: any; + i18nextDefered: any; constructor(ea: any, signaler: any); setup(options?: any): any; setLocale(locale: any): any; diff --git a/dist/es2015/i18n.js b/dist/es2015/i18n.js index c7f0e6db..27f3768c 100644 --- a/dist/es2015/i18n.js +++ b/dist/es2015/i18n.js @@ -5,11 +5,16 @@ export let I18N = class I18N { constructor(ea, signaler) { this.globalVars = {}; + this.i18nextDefered = { + resolve: null, + promise: null + }; this.i18next = i18next; this.ea = ea; this.Intl = window.Intl; this.signaler = signaler; + this.i18nextDefered.promise = new Promise(resolve => this.i18nextDefered.resolve = resolve); } setup(options) { @@ -22,15 +27,15 @@ export let I18N = class I18N { debug: false }; - return new Promise(resolve => { - i18next.init(options || defaultOptions, (err, t) => { - if (i18next.options.attributes instanceof String) { - i18next.options.attributes = [i18next.options.attributes]; - } + i18next.init(options || defaultOptions, (err, t) => { + if (i18next.options.attributes instanceof String) { + i18next.options.attributes = [i18next.options.attributes]; + } - resolve(this.i18next); - }); + this.i18nextDefered.resolve(this.i18next); }); + + return this.i18nextDefered.promise; } setLocale(locale) { @@ -111,6 +116,10 @@ export let I18N = class I18N { } updateValue(node, value, params) { + this.i18nextDefered.promise.then(() => this._updateValue(node, value, params)); + } + + _updateValue(node, value, params) { if (value === null || value === undefined) { return; } diff --git a/dist/system/aurelia-i18n.d.ts b/dist/system/aurelia-i18n.d.ts index 40206f46..352a0e6b 100644 --- a/dist/system/aurelia-i18n.d.ts +++ b/dist/system/aurelia-i18n.d.ts @@ -29,6 +29,7 @@ declare module 'aurelia-i18n' { /*eslint no-cond-assign: 0*/ export class I18N { globalVars: any; + i18nextDefered: any; constructor(ea: any, signaler: any); setup(options?: any): any; setLocale(locale: any): any; diff --git a/dist/system/i18n.js b/dist/system/i18n.js index 2295868c..2b099bb2 100644 --- a/dist/system/i18n.js +++ b/dist/system/i18n.js @@ -16,18 +16,27 @@ System.register(['i18next'], function (_export, _context) { execute: function () { _export('I18N', I18N = function () { function I18N(ea, signaler) { + var _this = this; + _classCallCheck(this, I18N); this.globalVars = {}; + this.i18nextDefered = { + resolve: null, + promise: null + }; this.i18next = i18next; this.ea = ea; this.Intl = window.Intl; this.signaler = signaler; + this.i18nextDefered.promise = new Promise(function (resolve) { + return _this.i18nextDefered.resolve = resolve; + }); } I18N.prototype.setup = function setup(options) { - var _this = this; + var _this2 = this; var defaultOptions = { compatibilityAPI: 'v1', @@ -38,25 +47,25 @@ System.register(['i18next'], function (_export, _context) { debug: false }; - return new Promise(function (resolve) { - i18next.init(options || defaultOptions, function (err, t) { - if (i18next.options.attributes instanceof String) { - i18next.options.attributes = [i18next.options.attributes]; - } + i18next.init(options || defaultOptions, function (err, t) { + if (i18next.options.attributes instanceof String) { + i18next.options.attributes = [i18next.options.attributes]; + } - resolve(_this.i18next); - }); + _this2.i18nextDefered.resolve(_this2.i18next); }); + + return this.i18nextDefered.promise; }; I18N.prototype.setLocale = function setLocale(locale) { - var _this2 = this; + var _this3 = this; return new Promise(function (resolve) { - var oldLocale = _this2.getLocale(); - _this2.i18next.changeLanguage(locale, function (err, tr) { - _this2.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); - _this2.signaler.signal('aurelia-translation-signal'); + var oldLocale = _this3.getLocale(); + _this3.i18next.changeLanguage(locale, function (err, tr) { + _this3.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); + _this3.signaler.signal('aurelia-translation-signal'); resolve(tr); }); }); @@ -130,6 +139,14 @@ System.register(['i18next'], function (_export, _context) { }; I18N.prototype.updateValue = function updateValue(node, value, params) { + var _this4 = this; + + this.i18nextDefered.promise.then(function () { + return _this4._updateValue(node, value, params); + }); + }; + + I18N.prototype._updateValue = function _updateValue(node, value, params) { if (value === null || value === undefined) { return; } diff --git a/dist/temp/aurelia-i18n.js b/dist/temp/aurelia-i18n.js index 8bbd7466..5628fa7f 100644 --- a/dist/temp/aurelia-i18n.js +++ b/dist/temp/aurelia-i18n.js @@ -317,18 +317,27 @@ var LazyOptional = exports.LazyOptional = (_dec = (0, _aureliaDependencyInjectio var I18N = exports.I18N = function () { function I18N(ea, signaler) { + var _this2 = this; + _classCallCheck(this, I18N); this.globalVars = {}; + this.i18nextDefered = { + resolve: null, + promise: null + }; this.i18next = _i18next2.default; this.ea = ea; this.Intl = window.Intl; this.signaler = signaler; + this.i18nextDefered.promise = new Promise(function (resolve) { + return _this2.i18nextDefered.resolve = resolve; + }); } I18N.prototype.setup = function setup(options) { - var _this2 = this; + var _this3 = this; var defaultOptions = { compatibilityAPI: 'v1', @@ -339,25 +348,25 @@ var I18N = exports.I18N = function () { debug: false }; - return new Promise(function (resolve) { - _i18next2.default.init(options || defaultOptions, function (err, t) { - if (_i18next2.default.options.attributes instanceof String) { - _i18next2.default.options.attributes = [_i18next2.default.options.attributes]; - } + _i18next2.default.init(options || defaultOptions, function (err, t) { + if (_i18next2.default.options.attributes instanceof String) { + _i18next2.default.options.attributes = [_i18next2.default.options.attributes]; + } - resolve(_this2.i18next); - }); + _this3.i18nextDefered.resolve(_this3.i18next); }); + + return this.i18nextDefered.promise; }; I18N.prototype.setLocale = function setLocale(locale) { - var _this3 = this; + var _this4 = this; return new Promise(function (resolve) { - var oldLocale = _this3.getLocale(); - _this3.i18next.changeLanguage(locale, function (err, tr) { - _this3.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); - _this3.signaler.signal('aurelia-translation-signal'); + var oldLocale = _this4.getLocale(); + _this4.i18next.changeLanguage(locale, function (err, tr) { + _this4.ea.publish('i18n:locale:changed', { oldValue: oldLocale, newValue: locale }); + _this4.signaler.signal('aurelia-translation-signal'); resolve(tr); }); }); @@ -431,6 +440,14 @@ var I18N = exports.I18N = function () { }; I18N.prototype.updateValue = function updateValue(node, value, params) { + var _this5 = this; + + this.i18nextDefered.promise.then(function () { + return _this5._updateValue(node, value, params); + }); + }; + + I18N.prototype._updateValue = function _updateValue(node, value, params) { if (value === null || value === undefined) { return; } @@ -486,7 +503,7 @@ var I18N = exports.I18N = function () { var BaseI18N = exports.BaseI18N = (_temp = _class3 = function () { function BaseI18N(i18n, element, ea) { - var _this4 = this; + var _this6 = this; _classCallCheck(this, BaseI18N); @@ -494,7 +511,7 @@ var BaseI18N = exports.BaseI18N = (_temp = _class3 = function () { this.element = element; this.__i18nDisposer = ea.subscribe('i18n:locale:changed', function () { - _this4.i18n.updateTranslations(_this4.element); + _this6.i18n.updateTranslations(_this6.element); }); } @@ -555,7 +572,7 @@ var RelativeTime = exports.RelativeTime = function () { }; function RelativeTime(i18n) { - var _this5 = this; + var _this7 = this; _classCallCheck(this, RelativeTime); @@ -573,7 +590,7 @@ var RelativeTime = exports.RelativeTime = function () { } } - _this5.service.i18next.addResources(key, 'translation', translation); + _this7.service.i18next.addResources(key, 'translation', translation); }); } @@ -659,19 +676,19 @@ var TCustomAttribute = exports.TCustomAttribute = (_dec3 = (0, _aureliaTemplatin } TCustomAttribute.prototype.bind = function bind() { - var _this6 = this; + var _this8 = this; this.params = this.lazyParams(); if (this.params) { this.params.valueChanged = function (newParams, oldParams) { - _this6.paramsChanged(_this6.value, newParams, oldParams); + _this8.paramsChanged(_this8.value, newParams, oldParams); }; } var p = this.params !== null ? this.params.value : undefined; this.subscription = this.ea.subscribe('i18n:locale:changed', function () { - _this6.service.updateValue(_this6.element, _this6.value, p); + _this8.service.updateValue(_this8.element, _this8.value, p); }); this.service.updateValue(this.element, this.value, p); diff --git a/src/i18n.js b/src/i18n.js index cd23088a..19921783 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -4,12 +4,17 @@ import i18next from 'i18next'; export class I18N { globalVars = {}; + i18nextDefered = { + resolve: null, + promise: null + }; constructor(ea, signaler) { this.i18next = i18next; this.ea = ea; this.Intl = window.Intl; this.signaler = signaler; + this.i18nextDefered.promise = new Promise((resolve) => this.i18nextDefered.resolve = resolve); } setup(options?) { @@ -22,16 +27,16 @@ export class I18N { debug: false }; - return new Promise((resolve) => { - i18next.init(options || defaultOptions, (err, t) => { - //make sure attributes is an array in case a string was provided - if (i18next.options.attributes instanceof String) { - i18next.options.attributes = [i18next.options.attributes]; - } + i18next.init(options || defaultOptions, (err, t) => { + //make sure attributes is an array in case a string was provided + if (i18next.options.attributes instanceof String) { + i18next.options.attributes = [i18next.options.attributes]; + } - resolve(this.i18next); - }); + this.i18nextDefered.resolve(this.i18next); }); + + return this.i18nextDefered.promise; } setLocale(locale) { @@ -130,6 +135,10 @@ export class I18N { } updateValue(node, value, params) { + this.i18nextDefered.promise.then(() => this._updateValue(node, value, params)); + } + + _updateValue(node, value, params) { if (value === null || value === undefined) { return; } diff --git a/test/unit/i18n.update-translations.spec.js b/test/unit/i18n.update-translations.spec.js index 133fa9fa..66646579 100644 --- a/test/unit/i18n.update-translations.spec.js +++ b/test/unit/i18n.update-translations.spec.js @@ -40,7 +40,7 @@ describe('testing i18n translation update', () => { ea = new EventAggregator(); sut = new I18N(ea, new BindingSignaler()); - sut.setup({ + let i18nextSetupPromise = sut.setup({ resources: resources, lng: 'en', attributes: ['t', 'data-i18n'], @@ -49,18 +49,19 @@ describe('testing i18n translation update', () => { }); //load the the html fixture - System.import('fixture:template.html!text').then((result) => { + let systemImportPromise = System.import('fixture:template.html!text').then((result) => { template = document.createElement('div'); template.innerHTML = result; if (template.firstChild instanceof HTMLTemplateElement) template.innerHTML = template.firstChild.innerHTML; document.body.appendChild(template); - done(); }); //update the translations in the template when the locale changes ea.subscribe('i18n:locale:changed', payload => { sut.updateTranslations(template); }); + + Promise.all([i18nextSetupPromise, systemImportPromise]).then(() => done()); }); @@ -92,85 +93,109 @@ describe('testing i18n translation update', () => { expect(template.querySelector('#test2').innerHTML.trim()).toBe('Description'); }); - it('should translate contents of elements with a translation attribute', () => { + it('should translate contents of elements with a translation attribute', done => { expect(template.querySelector('#test1').innerHTML.trim()).toBe('Title'); expect(template.querySelector('#test2').innerHTML.trim()).toBe('Description'); - sut.setLocale('de'); - expect(template.querySelector('#test1').innerHTML.trim()).toBe('Titel'); - expect(template.querySelector('#test2').innerHTML.trim()).toBe('Beschreibung'); + sut.setLocale('de').then(() => { + expect(template.querySelector('#test1').innerHTML.trim()).toBe('Titel'); + expect(template.querySelector('#test2').innerHTML.trim()).toBe('Beschreibung'); + done(); + }); }); - it('should translate nested keys', () => { + it('should translate nested keys', done => { expect(template.querySelector('#test-nested').innerHTML.trim()).toBe('Description Title'); - sut.setLocale('de'); - expect(template.querySelector('#test-nested').innerHTML.trim()).toBe('Der Titel ist der Kopf'); + sut.setLocale('de').then(() => { + expect(template.querySelector('#test-nested').innerHTML.trim()).toBe('Der Titel ist der Kopf'); + done(); + }); }); - it('should work with all attributes specified in the options', () => { + it('should work with all attributes specified in the options', done => { let el = template.querySelector('#test-other-attr'); expect(el.innerHTML.trim()).toBe('Description'); - sut.setLocale('de'); - expect(el.innerHTML.trim()).toBe('Beschreibung'); + sut.setLocale('de').then(() => { + expect(el.innerHTML.trim()).toBe('Beschreibung'); + done(); + }); }); - it('should set the textContent when using the [text] attribute', () => { + it('should set the textContent when using the [text] attribute', done => { let el = template.querySelector('#test-text'); expect(el.innerHTML.trim()).toBe('Description'); - sut.setLocale('de'); - expect(el.innerHTML.trim()).toBe('Beschreibung'); + sut.setLocale('de').then(() => { + expect(el.innerHTML.trim()).toBe('Beschreibung'); + done(); + }); }); - it('should escape html tags by default or when using [text]', () => { + it('should escape html tags by default or when using [text]', done => { let el = template.querySelector('#test-text-with-tags'); expect(el.innerHTML.trim()).toBe('Description with some bold'); - sut.setLocale('de'); - expect(el.innerHTML.trim()).toBe('Beschreibung <b>mit Fettdruck</b>'); + sut.setLocale('de').then(() => { + expect(el.innerHTML.trim()).toBe('Beschreibung <b>mit Fettdruck</b>'); + done(); + }); }); - it('should allow tags when using the [html] attribute', () => { + it('should allow tags when using the [html] attribute', done => { let el = template.querySelector('#test-html'); expect(el.innerHTML.trim()).toBe('Description with some bold'); - sut.setLocale('de'); - expect(el.innerHTML.trim()).toBe('Beschreibung mit Fettdruck'); + sut.setLocale('de').then(() => { + expect(el.innerHTML.trim()).toBe('Beschreibung mit Fettdruck'); + done(); + }); }); - it('should prepend the translation when using the [prepend] attribute, and it allows html', () => { + it('should prepend the translation when using the [prepend] attribute, and it allows html', done => { let el = template.querySelector('#test-prepend'); expect(el.innerHTML.trim()).toBe('content'); - sut.setLocale('de'); - expect(el.innerHTML.trim()).toBe('Beschreibung mit Fettdruckcontent'); - sut.setLocale('en'); - expect(el.innerHTML.trim()).toBe('Description with some boldcontent'); - }); + sut.setLocale('de').then(() => { + expect(el.innerHTML.trim()).toBe('Beschreibung mit Fettdruckcontent'); + return sut.setLocale('en'); + }).then(() => { + expect(el.innerHTML.trim()).toBe('Description with some boldcontent'); + done(); + }); + }); - it('should append the translation when using the [append] attribute, and it allows html', () => { + it('should append the translation when using the [append] attribute, and it allows html', done => { let el = template.querySelector('#test-append'); expect(el.innerHTML.trim()).toBe('content'); - sut.setLocale('de'); - expect(el.innerHTML.trim()).toBe('contentBeschreibung mit Fettdruck'); - sut.setLocale('en'); - expect(el.innerHTML.trim()).toBe('contentDescription with some bold'); + sut.setLocale('de').then(() => { + expect(el.innerHTML.trim()).toBe('contentBeschreibung mit Fettdruck'); + return sut.setLocale('en'); + }).then(() => { + expect(el.innerHTML.trim()).toBe('contentDescription with some bold'); + done(); + }); }); - it('should set multiple keys when separated with a semicolon', () => { + it('should set multiple keys when separated with a semicolon', done => { let el = template.querySelector('#test-multiple'); expect(el.innerHTML.trim()).toBe('Description with some bold'); expect(el.className).toBe(''); - sut.setLocale('de'); - expect(el.innerHTML.trim()).toBe('Beschreibung mit Fettdruck'); - expect(el.className).toBe('blue'); - sut.setLocale('en'); - expect(el.innerHTML.trim()).toBe('Description with some bold'); - expect(el.className).toBe('red'); + sut.setLocale('de').then(() => { + expect(el.innerHTML.trim()).toBe('Beschreibung mit Fettdruck'); + expect(el.className).toBe('blue'); + return sut.setLocale('en'); + }).then(() => { + expect(el.innerHTML.trim()).toBe('Description with some bold'); + expect(el.className).toBe('red'); + done(); + }); }); - it('should set the src attribute for images', () => { + it('should set the src attribute for images', done => { let el = template.querySelector('#test-img'); expect(el.getAttribute('src')).toBeNull(); - sut.setLocale('de'); - expect(el.getAttribute('src')).toBe('testimage-german.jpg'); - sut.setLocale('en'); - expect(el.getAttribute('src')).toBe('testimage-english.jpg'); + sut.setLocale('de').then(() => { + expect(el.getAttribute('src')).toBe('testimage-german.jpg'); + return sut.setLocale('en'); + }).then(() => { + expect(el.getAttribute('src')).toBe('testimage-english.jpg'); + done(); + }); }); });