【问题标题】:i18next and jest testing translations changesi18next 和 jest 测试翻译更改
【发布时间】:2019-01-29 21:31:41
【问题描述】:

您好,我尝试测试我修改后的 i18next 使用 jest 框架,我尝试测试默认语言,然后更改语言并接收正确的翻译

我的代码是这样的

const i18next = createI18nextContext();
//loading i18n files etc

i18next.on('loaded', () => {

    expect(i18next.t('test')).toBe('start-translations');

    changinglanguagefunction();
    expect(i18next.t('test')).toBe('changed-translations');
    done();
})

在那种情况下,我发现 i18 会产生 2 个威胁,所以我尝试使用,

18next.on('initialized', () => { 

然后我会超时。我怎样才能只得到一个威胁?

【问题讨论】:

标签: jestjs i18next


【解决方案1】:

一个解决方案是添加承诺

   function i18OnLoad(i18next: i18n.i18n) {
    return new Promise(resolve => {
    const loaded = () => {
    i18next.off("loaded", loaded);
    resolve();
    };
    i18next.on("loaded", loaded);
    });
    }

并添加

await i18NextOnLoad(i18next);

测试中

【讨论】:

    猜你喜欢
    • 2020-09-07
    • 2018-07-28
    • 1970-01-01
    • 2012-10-27
    • 2015-11-04
    • 1970-01-01
    • 2021-07-02
    • 2023-02-20
    • 2021-01-29
    相关资源
    最近更新 更多