testdouble.js
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.
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:
- Installation
- for Node.js
- for browsers
- initial configuration
- Purpose of testdouble.js
- in unit tests
- in integration tests
- Getting started tutorial
- Creating test doubles
- test double functions with
td.function()
- test double objects with
td.object()
1. objects that mirror a constructor function 2. objects that mirror an object of functions 3. object of functions for an array of names 4. object of any functions using ES2015 Proxy - Stubbing responses
- td.when() API
- equality argument matching
- one-liner stubbings
- stubbing sequential return values
- argument matchers 1. td.matchers.anything() 2. td.matchers.isA() 3. td.matchers.contains()
- Configuring stubbings 1. ignoreExtraArgs 2. times
- Verifying invocations
- td.verify() API
- equality argument matching
- argument matchers 1. td.matchers.anything() 2. td.matchers.isA() 3. td.matchers.contains()
- Argument captors
- Configuring verifications 1. ignoreExtraArgs 2. times
- Replacing dependencies with test doubles
- for Node.js 1. td.replace() API
- for Browser JS
- Writing custom argument matchers
- Debugging with testdouble.js
- td.explain() API
- Plugins
- testdouble-chai
- testdouble-jasmine
- Frequently Asked Questions
- Why doesn't
td.replace()
work with external CommonJS modules?