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

stub also verified warning when using ignoreExtraArgs #181

Closed
ackerdev opened this issue Jan 23, 2017 · 5 comments
Closed

stub also verified warning when using ignoreExtraArgs #181

ackerdev opened this issue Jan 23, 2017 · 5 comments

Comments

@ackerdev
Copy link

When attempting to create reusable doubles, I found an oddity with the behavior of the "test double was both stubbed and verified" warning when using ignoreExtraArgs.

As a simple (contrived) example:

const foo = td.function();

td.when(foo(), { ignoreExtraArgs: true }).thenReturn(bar);
td.verify(foo());

The intention behind this is to stub behavior of foo that consistently returns bar, regardless of arguments, while the verify call is to ensure that foo was called with 0 arguments. Because the stubbing is defined without arguments, the warning is displayed, even though ignoreExtraArgs should imply that these invocations are not 1-to-1 identical. It is possible to work around this with td.matchers.anything() in the stubbing, though not ideal.

My usecase for this is creating a reusable double to stand in for a somewhat complex third party interface that is passed in as an argument to my function; specifically, hapi's reply interface.

This is seems somewhat related to #180, a functionality limited by the stubbing api, though I think it's a distinct issue worth documenting.

@searls
Copy link
Member

searls commented Jan 24, 2017

This particular warning has been discussed in a lot of other threads if you want more on my thinking about this.

But I would suggest based on the other thread we were in yesterday that your use of the library is far enough outside the workflow I had in mind when designing it that you'll want to toggle the ignoreWarnings bit here.

@searls searls closed this as completed Jan 24, 2017
@ackerdev
Copy link
Author

Just to be clear, this issue isn't about the warning in general; I understand and agree with it. My point is that there is somewhat inconsistent behavior around the warning when using ignoreExtraArgs.

eg:

td.when(foo(), { ignoreExtraArgs: true }).thenReturn();
td.verify(foo()); // Warning!

td.when(bar(anything()), { ignoreExtraArgs: true }).thenReturn();
td.verify(bar()); // No warning

td.when(baz(), { ignoreExtraArgs: true }).thenReturn();
td.verify(baz(1)); // No warning

It seems the warning isn't taking into account the ignoreExtraArgs option. I'm not sure how it should behave even so, but just looked like it might be an unintentional inconsistency.

@searls searls reopened this Jan 26, 2017
@searls
Copy link
Member

searls commented Jan 26, 2017

This is indeed inconsistent and I can't explain it.

@searls searls added this to Need to Fix in Bugs & Requests Jan 26, 2017
samjonester added a commit to samjonester/testdouble.js that referenced this issue Mar 6, 2017
After a verification is made, a warning can be produced to signal that
the verification call matches a stub on the same testdouble. This
behavior is improved to test the verification against the stubbing using
the stubs matchers and config options.

This closes: stub also verified warning when using ignoreExtraArgs testdouble#181
completed with @tinney
samjonester added a commit to samjonester/testdouble.js that referenced this issue Mar 6, 2017
After a verification is made, a warning can be produced to signal that
the verification call matches a stub on the same testdouble. This
behavior is improved to test the verification against the stubbing using
the stubs matchers and config options.

This closes: stub also verified warning when using ignoreExtraArgs testdouble#181
completed with @tinney
@samjonester
Copy link
Contributor

@ackerdev Thanks for reporting the inconsistencies!

Here is my feeling about these cases:

// 1
// This should warn since the verify call foo() matches the stubbing exactly.
// Already working as expected.
td.when(foo(), { ignoreExtraArgs: true }).thenReturn()
foo()
td.verify(foo())

// 2
// This should not warn since the verification call doesn't match the stubbing.
// Already working as expected.
td.when(bar(anything()), { ignoreExtraArgs: true }).thenReturn()
bar()
td.verify(bar())

// 3
// This should warn since the verification matches the stubbing.
// Not currently working.
td.when(baz(), { ignoreExtraArgs: true }).thenReturn()
baz(1)
td.verify(baz(1))

This PR addresses case 3, which is inconsistent and currently failing. Check out the test cases, and please respond with any other edge cases that seem incorrect.

For more information on why case 2 doesn't match, please check the docs here.

@searls
Copy link
Member

searls commented Mar 6, 2017

i'm content with Sam's reasoning & PR above.

@searls searls closed this as completed Mar 6, 2017
@searls searls moved this from Need to Fix to Done in Bugs & Requests Apr 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

3 participants