chore: change to await localizeNamespacesLoaded + nextframe
This commit is contained in:
parent
c544af4eb9
commit
f843278c50
1 changed files with 27 additions and 20 deletions
|
|
@ -111,12 +111,12 @@ describe('LocalizeMixin', () => {
|
||||||
const wrapper = await fixture('<div></div>');
|
const wrapper = await fixture('<div></div>');
|
||||||
const onLocaleReadySpy = sinon.spy(el, 'onLocaleReady');
|
const onLocaleReadySpy = sinon.spy(el, 'onLocaleReady');
|
||||||
|
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
expect(onLocaleReadySpy.callCount).to.equal(0);
|
expect(onLocaleReadySpy.callCount).to.equal(0);
|
||||||
|
|
||||||
wrapper.appendChild(el);
|
wrapper.appendChild(el);
|
||||||
|
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
expect(onLocaleReadySpy.callCount).to.equal(1);
|
expect(onLocaleReadySpy.callCount).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -140,19 +140,17 @@ describe('LocalizeMixin', () => {
|
||||||
const wrapper = await fixture('<div></div>');
|
const wrapper = await fixture('<div></div>');
|
||||||
const onLocaleChangedSpy = sinon.spy(el, 'onLocaleChanged');
|
const onLocaleChangedSpy = sinon.spy(el, 'onLocaleChanged');
|
||||||
|
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
|
|
||||||
localize.locale = 'nl-NL';
|
localize.locale = 'nl-NL';
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
expect(onLocaleChangedSpy.callCount).to.equal(0);
|
expect(onLocaleChangedSpy.callCount).to.equal(0);
|
||||||
|
|
||||||
wrapper.appendChild(el);
|
wrapper.appendChild(el);
|
||||||
|
|
||||||
localize.locale = 'ru-RU';
|
localize.locale = 'ru-RU';
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
expect(onLocaleChangedSpy.callCount).to.equal(1);
|
expect(onLocaleChangedSpy.callCount).to.equal(1);
|
||||||
// FIXME: Expected 0 arguments, but got 2. ts(2554) --> not sure why this sinon type is not working
|
|
||||||
// @ts-expect-error
|
|
||||||
expect(onLocaleChangedSpy.calledWithExactly('ru-RU', 'nl-NL')).to.be.true;
|
expect(onLocaleChangedSpy.calledWithExactly('ru-RU', 'nl-NL')).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -167,7 +165,13 @@ describe('LocalizeMixin', () => {
|
||||||
return [myElementNs, ...super.localizeNamespaces];
|
return [myElementNs, ...super.localizeNamespaces];
|
||||||
}
|
}
|
||||||
|
|
||||||
onLocaleChanged() {
|
/**
|
||||||
|
* @param {string} newLocale
|
||||||
|
* @param {string} oldLocale
|
||||||
|
*/
|
||||||
|
onLocaleChanged(newLocale, oldLocale) {
|
||||||
|
super.onLocaleChanged(newLocale, oldLocale);
|
||||||
|
|
||||||
// Can call localize.msg immediately, without having to await localize.loadingComplete
|
// Can call localize.msg immediately, without having to await localize.loadingComplete
|
||||||
// This is because localeChanged event is fired only after awaiting loading
|
// This is because localeChanged event is fired only after awaiting loading
|
||||||
// unless the user disables _autoLoadOnLocaleChange property
|
// unless the user disables _autoLoadOnLocaleChange property
|
||||||
|
|
@ -183,15 +187,14 @@ describe('LocalizeMixin', () => {
|
||||||
const wrapper = await fixture('<div></div>');
|
const wrapper = await fixture('<div></div>');
|
||||||
wrapper.appendChild(el);
|
wrapper.appendChild(el);
|
||||||
|
|
||||||
await aTimeout(500);
|
|
||||||
|
|
||||||
localize.locale = 'nl-NL';
|
localize.locale = 'nl-NL';
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
|
await nextFrame();
|
||||||
expect(el.foo).to.equal('bar-nl-NL');
|
expect(el.foo).to.equal('bar-nl-NL');
|
||||||
|
|
||||||
localize.locale = 'ru-RU';
|
localize.locale = 'ru-RU';
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
|
await nextFrame();
|
||||||
expect(el.foo).to.equal('bar-ru-RU');
|
expect(el.foo).to.equal('bar-ru-RU');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -222,7 +225,8 @@ describe('LocalizeMixin', () => {
|
||||||
expect(onLocaleUpdatedSpy.callCount).to.equal(1);
|
expect(onLocaleUpdatedSpy.callCount).to.equal(1);
|
||||||
|
|
||||||
localize.locale = 'nl-NL';
|
localize.locale = 'nl-NL';
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
|
await nextFrame();
|
||||||
expect(onLocaleUpdatedSpy.callCount).to.equal(2);
|
expect(onLocaleUpdatedSpy.callCount).to.equal(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -261,7 +265,8 @@ describe('LocalizeMixin', () => {
|
||||||
expect(el.label).to.equal('one');
|
expect(el.label).to.equal('one');
|
||||||
|
|
||||||
localize.locale = 'nl-NL';
|
localize.locale = 'nl-NL';
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
|
await nextFrame();
|
||||||
expect(el.label).to.equal('two');
|
expect(el.label).to.equal('two');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -284,10 +289,10 @@ describe('LocalizeMixin', () => {
|
||||||
const updateSpy = sinon.spy(el, 'requestUpdate');
|
const updateSpy = sinon.spy(el, 'requestUpdate');
|
||||||
|
|
||||||
el.connectedCallback();
|
el.connectedCallback();
|
||||||
await el.localizeNamespacesLoaded;
|
|
||||||
|
|
||||||
localize.locale = 'nl-NL';
|
localize.locale = 'nl-NL';
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
|
await nextFrame();
|
||||||
expect(updateSpy.callCount).to.equal(1);
|
expect(updateSpy.callCount).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -419,8 +424,9 @@ describe('LocalizeMixin', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const tag = defineCE(MyLocalizedClass);
|
const tagName = defineCE(MyLocalizedClass);
|
||||||
const el = /** @type {MyLocalizedClass} */ (await fixture(`<${tag}></${tag}>`));
|
const tag = unsafeStatic(tagName);
|
||||||
|
const el = /** @type {MyLocalizedClass} */ (await fixture(html`<${tag}></${tag}>`));
|
||||||
await el.updateComplete;
|
await el.updateComplete;
|
||||||
|
|
||||||
expect(el.shadowRoot).to.exist;
|
expect(el.shadowRoot).to.exist;
|
||||||
|
|
@ -429,7 +435,8 @@ describe('LocalizeMixin', () => {
|
||||||
expect(p.innerText).to.equal('Hi!');
|
expect(p.innerText).to.equal('Hi!');
|
||||||
localize.locale = 'en-US';
|
localize.locale = 'en-US';
|
||||||
expect(p.innerText).to.equal('Hi!');
|
expect(p.innerText).to.equal('Hi!');
|
||||||
await localize.loadingComplete;
|
await el.localizeNamespacesLoaded;
|
||||||
|
await aTimeout(25); // needed because msgLit relies on until directive
|
||||||
await el.updateComplete;
|
await el.updateComplete;
|
||||||
expect(p.innerText).to.equal('Howdy!');
|
expect(p.innerText).to.equal('Howdy!');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue