简体   繁体   English

如何用 Jest Javascript React Native 模拟“替换”function?

[英]How to mock 'replace' function with Jest Javascript React Native?

I use Jest as unit testing on the React Native App I created.我使用 Jest 作为我创建的 React Native App 的单元测试。 For currency formatting purposes I use the 'replace' function from Javascript as below:出于货币格式化目的,我使用 Javascript 中的“替换” function 如下:

This my code:这是我的代码:

amount.replace(/(\d)(?=(\d{3})+(?!\d))/g,'$1.',)

I'm getting a 'TypeError: Cannot read property' replace 'of undefined' while running my TDD Jest我在运行我的 TDD Jest 时收到“类型错误:无法读取属性”替换“未定义”

Please help, thank you请帮忙,谢谢

Already Solved, Because I Using Props.已经解决了,因为我使用了道具。

Show The Solution is you make a default value first for handling that before the data already sent.显示解决方案是在数据已经发送之前先设置一个默认值来处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM