【发布时间】:2019-03-21 12:54:43
【问题描述】:
我真的需要一些帮助来弄清楚为什么“.localize()”不能与我的 Jest 测试套件一起使用。在各种测试中,我总是得到一个不及格的测试结果,因为显然 “$(...).localize 不是函数”。
我的 jestSetup 文件有 global.localize = jest.fn();
问题似乎是我会有这样的事情:
it('should update with the right animal', () => {
document.body.innerHTML =
`<div class='hopScotch'></div>`
superFunctionMango('OWL')
expect($('.hopScotch').attr('data-
i18n')).toBe('OWL.#')
//and it allpasses except for app.localize
})
superFunctionMango 在实际的 js 文件中是这样的:
function updateNewInvoiceFieldsWithCorrectDocType(bird) {
$("#newBarBird").attr("data-i18n", `${bird}.new`);
$(".newBirdTitle").attr("data-i18n",
`${bird}.#`);
$(".newBirdDate").attr("data-i18n",
`${bird}.date`);
$(".newBirdSelect").attr("data-i18n", `${bird}.name`);
$("#app").localize();
}
$('#app').localize() 似乎总是把事情搞砸。做什么?
【问题讨论】:
标签: javascript internationalization jestjs i18next