question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What's the best way to use testdouble.js with tape?

See original GitHub issue

I saw https://github.com/testdouble/testdouble.js/issues/33 but it’s quite verbose to use testdouble with tape:

const test = require('tape');
const td = require('testdouble');

test('verify invoked', function(t) {
  t.plan(1)

  var stub = td.create()

  stub('any arguments', 0, 1, 2)

  t.doesNotThrow(function() {
    td.verify(stub0())
  }, 'called with more arguments when none are specified')
})

Anyway to not pass a callback to t.doesNotThrow?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
customcommandercommented, Nov 10, 2021

If you really want to use t.plan(…) then I suggest you also use t.pass(…):

const test = require('tape');
const td = require('testdouble');
const SUT = require(/* … */); // Subject Under Test

test('Hello World!', t => {
  t.plan(1);
  const fn = td.func();
  SUT(fn, 42);
  td.verify(fn(42));
  t.pass('fn was applied to 42'); // <-- Counts towards t.plan
  t.end();
});

TAP Output:

# Hello World!
ok 1 fn was applied to 42
0reactions
searlscommented, Apr 1, 2016

Because td.verify throws an error, one option might be to use tape-catch: https://github.com/michaelrhodes/tape-catch

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Started | testdouble.js - GitHub Pages
This document provides a walk-through of one way to use testdouble.js, but some folks have indicated to us that it was not a...
Read more >
testdouble.js vs TwistedTrial comparison of testing frameworks
What are the differences between testdouble.js and TwistedTrial? Alternatives for testing frameworks in JavaScript and Python.
Read more >
Testing JavaScript Modules with Tape - Ponyfoo
Using tape, proxyquire, and sinon is the best possible combination of ... how to use them, what each of them is good for,...
Read more >
What you need to know about ES modules in Node.js
Confused about ES module support in Node.js? ... post isn't going to cover much about what ECMAScript (ES) modules are or how to...
Read more >
Nodejs HAPI Tape Pre Unit test - Stack Overflow
Using the Tape and Test Double Libraries for testing test('drayage/recommend-ramps route: should return 201 when successfully processed', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found