GithubHelp home page GithubHelp logo

miyu / testdouble.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from testdouble/testdouble.js

0.0 2.0 0.0 1.97 MB

A minimal test double library for TDD with JavaScript

License: MIT License

JavaScript 48.37% Shell 1.47% CoffeeScript 48.90% TypeScript 1.27%

testdouble.js's Introduction

testdouble.js

Build Status npmjs Test Coverage

Welcome! Are you writing JavaScript tests and in the market for a mocking library to fake out real things for you? testdouble.js is an opinionated, carefully-designed test double library maintained by, oddly enough, a software agency that's also named Test Double.

If you practice test-driven development, testdouble.js was designed to promote terse, clear, and easy-to-understand tests. There's an awful lot to cover, so please take some time and enjoy our documentation, which itself is designed to show you how to make the most out of test doubles in your tests.

The pitch

Interested in learning what testdouble.js is, why it exists, and what the API offers? The quickest path is this fast-paced 20-minute talk:

screenshot of testdouble.js talk

Coming from Sinon.js?

Right now, Sinon.js is the test double incumbent in JavaScript, with over 1.7 million downloads in the last month. If you've got experience with Sinon, check out our side-by-side comparison to see why we wrote testdouble.js and how some of the API translates.

The Very Basics

Before diving into our in-depth docs, here is a quick intro of the basic uses:

Stubbing return values for functions

var td = require('testdouble');

var fetch = td.function();
td.when(fetch(42)).thenReturn('Jane User');

fetch(42); // -> 'Jane User'

Verifying a function was invoked

var td = require('testdouble');

var save = td.function('.save');
save(41, 'Jane');

td.verify(save(41, 'Jill'));
//
// Error: Unsatisfied verification on test double `.save`.
//
//   Wanted:
//     - called with `(41, "Jill")`.
//
//   But was actually called:
//     - called with `(41, "Jane")`.

Docs

All of our docs are in the docs/ directory inside this repository and numbered for easy reading in the priority-order we anticipate people needing them. Here's a rough outline:

  1. Installation
  2. for Node.js
  3. for browsers
  4. initial configuration
  5. Purpose of testdouble.js
  6. in unit tests
  7. in integration tests
  8. Getting started tutorial
  9. Creating test doubles
  10. test double functions with td.function()
  11. test double objects with td.object()
  12. test double constructors with td.constructor()
  13. Stubbing responses
  14. td.when() API
  15. equality argument matching
  16. one-liner stubbings
  17. stubbing sequential return values
  18. argument matchers 1. td.matchers.anything() 2. td.matchers.isA() 3. td.matchers.contains()
    1. matching strings
    2. matching arrays
    3. matching objects 4. td.matchers.argThat() 5. td.matchers.not()
  19. Stubbing callback APIs
  20. Stub exceptions with thenThrow
  21. Stub promises with thenResolve and thenReject
  22. Stub side effects with thenDo
  23. Configuring stubbings 1. ignoreExtraArgs 2. times 3. defer 4. delay
  24. Verifying invocations
  25. td.verify() API
  26. equality argument matching
  27. argument matchers 1. td.matchers.anything() 2. td.matchers.isA() 3. td.matchers.contains()
    1. matching strings
    2. matching arrays
    3. matching objects 4. td.matchers.argThat()
  28. Argument captors
  29. Configuring verifications 1. ignoreExtraArgs 2. times
  30. Replacing dependencies with test doubles
  31. for Node.js
  32. for Browser JS
  33. td.replace() API
  34. Writing custom argument matchers
  35. Debugging with testdouble.js
  36. td.explain() API
  37. Plugins
  38. testdouble-chai
  39. testdouble-jasmine
  40. Frequently Asked Questions
  41. Why doesn't td.replace() work with external CommonJS modules?
  42. Configuration
  43. td.config

testdouble.js's People

Contributors

searls avatar jasonkarns avatar samjonester avatar marchaos avatar mkusher avatar duluca avatar hanneskaeufler avatar turbo87 avatar miyu avatar briangenisio avatar jakxz avatar schoonology avatar andrewvida avatar caseyhoward avatar connor4312 avatar davemo avatar moeriki avatar monkbroc avatar lumaxis avatar verdammelt avatar ghedamat avatar randycoulman avatar kuy avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.