Compare string parameter with toHaveBeenCalledWith(regexp) #243

brabadu opened this Issue Jun 18, 2012 · 5 comments


None yet

4 participants

brabadu commented Jun 18, 2012


I couldn't find a way to check a string that was passed to a function with toHaveBeenCalledWith, using a regexp.

In particular, I'm passing URL with timestamp, and I'd like to validate it with something like

In code I have:

GET('/post?' + (new Date()).getTime())

In test want to do something like:


Is there any way to do this or, at least, check a string argument with regexp?




I am not sure whether @pivotal will see this issue, but in the meantime, you may use Spy#mostRecentCall.args in combination with the Matchers#toMatch regexp matcher to accomplish this.

I have created a stackoverflow question about this.

infews commented May 27, 2013

Would something like this be OK:

expect(GET).toHaveBeenCalledWith(jasmine.regExp(/foobar/)); ?

Using something like jasmine.any here makes things simpler at implementation time.


We've made a tracker story for this. You can follow along here:

@slackersoft slackersoft closed this Oct 2, 2013

Thanks for the heads up @slackersoft. 👍

@slackersoft slackersoft added a commit that referenced this issue Dec 19, 2014
@slackersoft slackersoft Add asymmetric equality tester to match a string against a regexp
- Also move the asymmetric testers into their own dir for easier

[#58120558] Fix #243
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment