You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a class with a create and update method, and I want to verify the correct one is called in certain scenarios.
Issue
Both create and update methods are stubbed functions. Neither has a return value. In my test, I am using td.verify(client.create()). This works, but it gives the warning about using td.when and td.verify together.
Is there a better way to verify that client.create has been called and client.update has not?
The text was updated successfully, but these errors were encountered:
boblauer
changed the title
How do I verify only one of 2 stubbed functions was called?
How do I verify only 1 of 2 stubbed functions was called?
Oct 4, 2018
here's a demo script that demonstrates what you are asking:
consttd=require('testdouble')constapp={client: {create(){},update(){}}}constsubject=()=>{app.client.create('lol')}// Imagined test codetd.replace(app,'client')subject()td.verify(app.client.create('lol'))td.verify(app.client.update(),{times: 0,ignoreExtraArgs: true})// Alternatively you can just make sure it wasn't called by inspecting it:require('assert').equal(td.explain(app.client.update).callCount,0)// Don't forget to have reset called in an afterEach hook somewheretd.reset()
Description
I have a class with a
create
andupdate
method, and I want to verify the correct one is called in certain scenarios.Issue
Both
create
andupdate
methods are stubbed functions. Neither has a return value. In my test, I am usingtd.verify(client.create())
. This works, but it gives the warning about usingtd.when
andtd.verify
together.Is there a better way to verify that
client.create
has been called andclient.update
has not?The text was updated successfully, but these errors were encountered: