在Jest中不匹配的相同字符串

以下测试失败:

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()进行断言,得出相同的结果。

断言上面两个字符串的正确方法是什么?

timberjack 回答:在Jest中不匹配的相同字符串

它在输出中返回一个不间断的空格,因此您也需要检查

expect(result).toEqual('1\xa0000\xa0kr')
本文链接:https://www.f2er.com/3136719.html

大家都在问