Search code examples
javascriptreactjsreact-nativejestjstdd

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


I use Jest as unit testing on the React Native App I created. For currency formatting purposes I use the 'replace' function from Javascript as below:

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

Please help, thank you


Solution

  • Already Solved, Because I Using Props.

    Show The Solution is you make a default value first for handling that before the data already sent.