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

Flexible parameters #110

Closed
phzbox opened this issue Jun 7, 2016 · 1 comment
Closed

Flexible parameters #110

phzbox opened this issue Jun 7, 2016 · 1 comment

Comments

@phzbox
Copy link

phzbox commented Jun 7, 2016

Is there a matcher to return a value from literally any kind of parameters, such as:

  let f = td.func()
  td.when(f(???)).thenReturn('abc')

  f() // abc
  f('a') // abc
  f(1,2,3) // abc

The only way I found was to do:

  let f = td.func()
  let anything = td.matchers.anything

  td.when(f()).thenReturn('abc')
  td.when(f(anything())).thenReturn('abc')
  td.when(f(anything(), anything(), anything())).thenReturn('abc')
@searls
Copy link
Member

searls commented Jun 8, 2016

You're looking for the ignoreExtraArgs Option.

td.when(f(), {ignoreExtraArgs: true}).thenReturen(5)

It's documented in the chapter on when stubbing

@searls searls closed this as completed Jun 8, 2016
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

2 participants