Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare string parameter with toHaveBeenCalledWith(regexp) #243

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

Compare string parameter with toHaveBeenCalledWith(regexp) #243

brabadu opened this issue Jun 18, 2012 · 5 comments

Comments

@brabadu
Copy link

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
Copy link

👍

@zealoushacker
Copy link

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
Copy link
Contributor

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
Copy link
Member

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

@zealoushacker
Copy link

Thanks for the heads up @slackersoft. 👍

slackersoft pushed a commit that referenced this issue Dec 19, 2014
- Also move the asymmetric testers into their own dir for easier
  locating.

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

No branches or pull requests

4 participants