Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

testdouble

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

testdouble - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

9

package.json
{
"name": "testdouble",
"version": "0.0.5",
"version": "0.1.0",
"description": "A minimal test double library for TDD with JavaScript",

@@ -8,3 +8,4 @@ "homepage": "https://github.com/testdouble/testdouble.js",

"name": "Justin Searls",
"company": "Test Double, LLC"
"email": "justin@testdouble.com",
"url": "http://testdouble.com"
},

@@ -14,4 +15,4 @@ "scripts": {

"test-debug": "mocha --debug-brk --ui mocha-gwt --recursive --require coffee-script --compilers coffee:coffee-script/register 'test/helper.coffee' 'test/'",
"preversion": "npm test",
"postversion": "npm publish"
"preversion": "git pull --rebase && npm test",
"postversion": "git push && git push --tags && npm publish"
},

@@ -18,0 +19,0 @@ "dependencies": {

@@ -19,13 +19,54 @@ # testdouble.js

## Stub with `when()`
## Create with `create()`
To stub with testdouble.js, first require it:
The easiest way to create a test double function is to make one anonymously:
```
var td = require('testdouble');
var myTestDouble = td.create();
```
Create a test double with the `create` function:
In the above, `myTestDouble` will be able to be stubbed or verified as shown below.
### Naming your test double
For slightly easier-to-understand error messages (with the trade-off of greater
redundancy in your tests), you can supply a string name to `create`
```
var myNamedDouble = td.create("#foo");
```
All error messages and descriptions provided for the above `myNamedDouble` will
also print the name `#foo`.
### Creating test doubles for an entire type
It's very typical that the code under test will depend not only on a single
function, but on an object type that's full of them.
Suppose your subject has a dependency:
``` javascript
function Dog() {};
Dog.prototype.bark = function(){};
Dog.prototype.bite = function(){};
```
Then you can create a test double of `Dog` with:
``` javascript
var myDogDouble = td.create(Dog)
```
This will return a plain object with `bark` and `byte` test double functions,
ready to be stubbed or verified and named `"Dog#bark"` and `"Dog#bite"`,
respectively.
## Stub with `when()`
To stub values with testdouble.js, first create one:
```
var td = require('testdouble');
myTestDouble = td.create();

@@ -93,51 +134,2 @@ ```

## Debug with `explain()`
One shortcoming of lots of JavaScript test double libraries is pretty rotten
introspection and output. While this library is generally pretty minimal, some
data about your test doubles can be gleaned by passing them to a top-level
`explain` function, like so:
``` javascript
var td = require('testdouble');
var myTestDouble = td.create();
td.explain(myTestDouble); /*
Returns:
{
callCount: 0,
calls: [],
description: 'This test double has 0 stubbings and 0 invocations.'
}
*/
```
If the test double does have stubbings or invocations, they'll be listed in the
description body for nicer error output.
## Configuration
The library is not coupled to any test framework, which means it can be used with
jasmine, QUnit, Mocha, or anything else. However, to get the most out of the library,
you may choose to make a few of the top-level functions global in a test helper
(to cut down on repetitive typing).
Perhaps you want to keep everything namespaced under `td` for short:
```
global.td = require('testdouble');
```
Or, you might prefer to plop the methods directly on the global:
```
global.double = require('testdouble').create;
global.when = require('testdouble').when;
global.verify = require('testdouble').verify;
```
Organize it however you like, being mindful that sprinkling in globals might save
on per-test setup cost, but at the expense of increased indirection for folks
unfamiliar with the test suite's setup.
## Argument matchers in `matchers`

@@ -155,2 +147,4 @@

You can see the built-in matchers in the [source](https://github.com/testdouble/testdouble.js/blob/master/lib/matchers.coffee).
Here's an example usage of the provided `isA()` matcher:

@@ -202,4 +196,53 @@

## Debug with `explain()`
One shortcoming of lots of JavaScript test double libraries is pretty rotten
introspection and output. While this library is generally pretty minimal, some
data about your test doubles can be gleaned by passing them to a top-level
`explain` function, like so:
``` javascript
var td = require('testdouble');
var myTestDouble = td.create();
td.explain(myTestDouble); /*
Returns:
{
callCount: 0,
calls: [],
description: 'This test double has 0 stubbings and 0 invocations.'
}
*/
```
If the test double does have stubbings or invocations, they'll be listed in the
description body for nicer error output.
## Configuration
The library is not coupled to any test framework, which means it can be used with
jasmine, QUnit, Mocha, or anything else. However, to get the most out of the library,
you may choose to make a few of the top-level functions global in a test helper
(to cut down on repetitive typing).
Perhaps you want to keep everything namespaced under `td` for short:
```
global.td = require('testdouble');
```
Or, you might prefer to plop the methods directly on the global:
```
global.double = require('testdouble').create;
global.when = require('testdouble').when;
global.verify = require('testdouble').verify;
```
Organize it however you like, being mindful that sprinkling in globals might save
on per-test setup cost, but at the expense of increased indirection for folks
unfamiliar with the test suite's setup.
## Unfinished business
The rest of the stuff we'd like to do with this is a work-in-progress. See the [issues](https://github.com/testdouble/testdouble.js/issues) for more detail on where we're headed.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc