Compare string parameter with toHaveBeenCalledWith(regexp) #243

Closed
brabadu opened this Issue Jun 18, 2012 · 5 comments

Projects

None yet

4 participants

@brabadu
brabadu commented Jun 18, 2012

Hi!

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:

expect(GET).toHaveBeenCalledWith(/\/post?\d+/)

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

@zealoushacker

👍

@zealoushacker

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
Collaborator
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.

@slackersoft
Member

We've made a tracker story for this. You can follow along here: https://www.pivotaltracker.com/story/show/58120558

@slackersoft slackersoft closed this Oct 2, 2013
@zealoushacker

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
  locating.

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