Intl.NumberFormat space character does not match

前端 未结 2 1429
礼貌的吻别
礼貌的吻别 2020-12-11 08:39

I\'m running into an issue where Intl.NumberFormat is formatting the space character in some way that is different from what Jest is expecting. Tests against t

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 09:10

    '11 111.11'.split('').map(x => console.log((x.charCodeAt(0))))
    

    Yields "32" for the space character which is a normal space.

    new Intl.NumberFormat('fr-CA').format(11111.11).split('').map(x => console.log((x.charCodeAt(0))))
    

    Yields "160" for the space character, which is a non-breaking space.

    To make these tests pass, you need to add the non-breaking space UTF-16 (\xa0) character code into the assertion.

    expect(formatCurrency(24555.55, 'fr_CA', true)).toBe('24\xa0555,55 $');
    

提交回复
热议问题