有没有办法让“ toHaveBeenCalledWith”匹配一个正则表达式?

Tol*_*oli 8 jestjs

我有一个函数,它附加一个随机数,然后调用另一个函数。我想检查传递的文本是否被调用并匹配任何随机数。我希望能够通过不带Jest真正匹配正则表达式的正则表达式。就像是:

 const typeFn = jest.fn();

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


 type('hello')
 expect(typeFn).toHaveBeenCalledWith(/hello\d+/)
Run Code Online (Sandbox Code Playgroud)

mar*_*lin 10

toHaveBeenCalledWith原谅中expect.stringMatching(/hello\d+/)

这是实时示例:https : //repl.it/@marzelin/FrighteningCapitalConferences