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

How do I verify only 1 of 2 stubbed functions was called? #384

Closed
boblauer opened this issue Oct 4, 2018 · 1 comment
Closed

How do I verify only 1 of 2 stubbed functions was called? #384

boblauer opened this issue Oct 4, 2018 · 1 comment

Comments

@boblauer
Copy link

boblauer commented Oct 4, 2018

Description

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?

@boblauer 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
@searls
Copy link
Member

searls commented Oct 8, 2018

Hi @boblauer.

here's a demo script that demonstrates what you are asking:

const td = require('testdouble')

const app = {
  client: {
    create () {},
    update () {}
  }
}

const subject = () => {
  app.client.create('lol')
}

// Imagined test code
td.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 somewhere
td.reset()

Relevant docs here

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