Is there a way to have `toHaveBeenCalledWith` match a regular expression?

Viewed 7351

I have a function that appends a random number an then calls another function. I want to check that it was called with the text passed in and match any random number. I'd like to be able to pass a Regex without Jest literally matching the Regex. Something like:

 const typeFn = jest.fn();

 function type (text) {
     typeFn(text + Math.random());
 })


 type('hello')
 expect(typeFn).toHaveBeenCalledWith(/hello\d+/)
1 Answers
Related