【发布时间】:2019-11-11 06:06:32
【问题描述】:
以下测试失败:
test('', () => {
const result = new Intl.NumberFormat('sv-SE', {
style: 'currency',
currency: 'SEK',
minimumFractionDigits: 0,
maximumFractionDigits: 0,
}).format(1000)
expect(result).toEqual('1 000 kr')
})
它返回以下提示:
Expected: "1 000 kr"
Received: "1 000 kr"
我也尝试过使用.toBe() 进行断言,结果相同。
断言上面两个字符串的正确方法是什么?
【问题讨论】:
-
尝试使用
encodeURIComponent(),看看有什么不同,要么记录它,要么只是为了方便,更改测试expect(encodeURIComponent(result)).toEqual(encodeURIComponent('1 000 kr')) -
我认为这是一个不间断的空间
-
我明白了。这太令人困惑了。你知道
Intl.NumberFormat返回这些字符的原因,以及没有它们的任何方法吗? (而不是在断言中使用encodeURIComponent)。 -
实际上,Intl 返回 no-br 空间是有意义的,所以最好不要与之抗争。没有人愿意在不同的行上看到“1000”和“$”。
标签: javascript string jestjs