各位提交者们好!
也许您在 jest 中验证字符串时遇到了问题。

例如,上面的测试验证函数接收一个值并返回一个四舍五入的值。
it('it should properly format a unit value with rounding.', () => { expect(formatcurrency(1234.56, true, false)).toequal({ measure: 'thousand', value: 'r$ 1.200,00', }); });
在这个测试中,jest 返回了一个错误,突出显示了预期值和接收到的值之间的差异,但它们是相同的 ?
- expected - 1+ received + 1 object { "measure": "thousand",- "value": "r$ 1.200,00",+ "value": "r$ 1.200,00",
解决办法是添加xa0。问题不在于你的字符串,而在于 jest 如何比较字符串值?
更正后的代码如上所示。
it('It should properly format a unit value with rounding.', () => { expect(formatCurrency(1234.56, true, false)).toEqual({ measure: 'thousand', value: 'R$xa01.200,00', // remove space and add xa0 }); });
以上就是在 Jest 中验证字符串的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1490200.html
微信扫一扫
支付宝扫一扫