testdouble
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -11,3 +11,3 @@ // Generated by CoffeeScript 1.10.0 | ||
Given(function() { | ||
return this.testDouble = requireSubject('lib/create')(); | ||
return this.testDouble = requireSubject('lib/function')(); | ||
}); | ||
@@ -14,0 +14,0 @@ Given(function() { |
@@ -8,3 +8,3 @@ // Generated by CoffeeScript 1.10.0 | ||
Given(function() { | ||
return this.create = requireSubject('lib/create'); | ||
return this["function"] = requireSubject('lib/function'); | ||
}); | ||
@@ -15,3 +15,3 @@ Given(function() { | ||
Given(function() { | ||
return this.testDouble = this.create(); | ||
return this.testDouble = this["function"](); | ||
}); | ||
@@ -32,3 +32,3 @@ When(function() { | ||
Given(function() { | ||
return this.testDouble = this.create("foobaby"); | ||
return this.testDouble = this["function"]("foobaby"); | ||
}); | ||
@@ -35,0 +35,0 @@ return Then(function() { |
@@ -15,5 +15,8 @@ // Generated by CoffeeScript 1.10.0 | ||
Then(function() { | ||
return this.subject.create === requireSubject('lib/create'); | ||
return this.subject["function"] === requireSubject('lib/function'); | ||
}); | ||
Then(function() { | ||
return this.subject.object === requireSubject('lib/object'); | ||
}); | ||
Then(function() { | ||
return this.subject.matchers === requireSubject('lib/matchers'); | ||
@@ -20,0 +23,0 @@ }); |
@@ -8,7 +8,10 @@ // Generated by CoffeeScript 1.10.0 | ||
Given(function() { | ||
return this.create = requireSubject('lib/create'); | ||
return this["function"] = requireSubject('lib/function'); | ||
}); | ||
Given(function() { | ||
return this.testDouble = this.create(); | ||
return this.object = requireSubject('lib/object'); | ||
}); | ||
Given(function() { | ||
return this.testDouble = this["function"](); | ||
}); | ||
context('a satisfied verification', function() { | ||
@@ -57,3 +60,3 @@ When(function() { | ||
Given(function() { | ||
return this.testDouble = this.create("#footime"); | ||
return this.testDouble = this["function"]("#footime"); | ||
}); | ||
@@ -85,3 +88,3 @@ When(function() { | ||
Given(function() { | ||
return this.testDoubleObj = this.create(this.SomeType); | ||
return this.testDoubleObj = this.object(this.SomeType); | ||
}); | ||
@@ -104,3 +107,3 @@ When(function() { | ||
Given(function() { | ||
return this.testDouble = this.create(); | ||
return this.testDouble = this["function"](); | ||
}); | ||
@@ -116,3 +119,3 @@ When(function() { | ||
Given(function() { | ||
return this.someTestDoubleArg = this.create(); | ||
return this.someTestDoubleArg = this["function"](); | ||
}); | ||
@@ -125,3 +128,3 @@ return Then(function() { | ||
Given(function() { | ||
return this.someTestDoubleArg = this.create("#foo"); | ||
return this.someTestDoubleArg = this["function"]("#foo"); | ||
}); | ||
@@ -128,0 +131,0 @@ return Then(function() { |
@@ -8,6 +8,6 @@ // Generated by CoffeeScript 1.10.0 | ||
Given(function() { | ||
return this.create = requireSubject('lib/create'); | ||
return this["function"] = requireSubject('lib/function'); | ||
}); | ||
Given(function() { | ||
return this.testDouble = this.create(); | ||
return this.testDouble = this["function"](); | ||
}); | ||
@@ -92,6 +92,6 @@ describe('no-arg stubbing', function() { | ||
Given(function() { | ||
return this.td1 = this.when(this.create()()).thenReturn("lol1"); | ||
return this.td1 = this.when(this["function"]()()).thenReturn("lol1"); | ||
}); | ||
Given(function() { | ||
return this.td2 = this.when(this.create()()).thenReturn("lol2"); | ||
return this.td2 = this.when(this["function"]()()).thenReturn("lol2"); | ||
}); | ||
@@ -98,0 +98,0 @@ Then(function() { |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
module.exports = { | ||
create: require('./create'), | ||
"function": require('./function'), | ||
object: require('./object'), | ||
when: require('./when'), | ||
@@ -6,0 +7,0 @@ verify: require('./verify'), |
{ | ||
"name": "testdouble", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "A minimal test double library for TDD with JavaScript", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/testdouble/testdouble.js", |
@@ -21,4 +21,6 @@ # testdouble.js | ||
## Create with `create()` | ||
## Creating Test Doubles | ||
### Creating test double functions with `function()` | ||
The easiest way to create a test double function is to make one anonymously: | ||
@@ -28,3 +30,3 @@ | ||
var td = require('testdouble'); | ||
var myTestDouble = td.create(); | ||
var myTestDouble = td.function(); | ||
``` | ||
@@ -34,3 +36,3 @@ | ||
### Naming your test double | ||
#### Naming your test double | ||
@@ -41,3 +43,3 @@ For slightly easier-to-understand error messages (with the trade-off of greater | ||
``` javascript | ||
var myNamedDouble = td.create("#foo"); | ||
var myNamedDouble = td.function("#foo"); | ||
``` | ||
@@ -48,3 +50,3 @@ | ||
### Creating test doubles for an entire type | ||
### Creating test doubles objects with `object()` | ||
@@ -54,2 +56,49 @@ It's very typical that the code under test will depend not only on a single | ||
#### Dynamic test double objects | ||
If your tests run under ES2015 or later and [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) | ||
is available (as of 2015/10/26: only under MS Edge & Firefox) in your JS runtime, | ||
then test double can create a test double object that can set up stubbings or | ||
verify function invocations for any name, completely dynamically! | ||
``` javascript | ||
var cat = td.object('Cat') | ||
td.when(cat.meow()).thenReturn('purr') | ||
cat.meow() // returns 'purr' | ||
cat.literallyAnythingAtAll() // undefined | ||
``` | ||
##### Excluding certain methods from the double | ||
Sometimes, your subject code will check to see if a property is defined, which | ||
may make a bit of code unreachable when a dynamic test double responds to every | ||
single accessed property. | ||
For example, if you have this code: | ||
``` javascript | ||
function leftovers(walrus) { | ||
if(!walrus.eat) { | ||
return 'cheese'; | ||
} | ||
} | ||
``` | ||
You could create a test double walrus that can reach the cheese with this: | ||
``` javascript | ||
walrus = td.object('Walrus', {excludeMethods: ['eat']}); | ||
leftovers(walrus) // 'cheese' | ||
``` | ||
By default, `excludeMethods` is set to `['then']`, so that test libraries like | ||
Mocha don't mistake every test double object for a Promise (which would cause the | ||
test suite to time out) | ||
#### Mirroring an instantiable type | ||
Suppose your subject has a dependency: | ||
@@ -66,3 +115,3 @@ | ||
``` javascript | ||
var myDogDouble = td.create(Dog) | ||
var myDogDouble = td.object(Dog) | ||
``` | ||
@@ -80,3 +129,3 @@ | ||
var td = require('testdouble'); | ||
myTestDouble = td.create(); | ||
myTestDouble = td.function(); | ||
``` | ||
@@ -117,3 +166,3 @@ | ||
var td = require('testdouble'); | ||
var myTestDouble = td.create(); | ||
var myTestDouble = td.function(); | ||
``` | ||
@@ -162,3 +211,3 @@ | ||
var td = require('testdouble'); | ||
var myTestDouble = td.create(); | ||
var myTestDouble = td.function(); | ||
@@ -244,4 +293,4 @@ when(myTestDouble(td.matchers.isA(String))).thenReturn("YES"); | ||
assert = require('assert'), | ||
logger = td.create('logger'), | ||
fetcher = td.create('fetcher'), | ||
logger = td.function('logger'), | ||
fetcher = td.function('fetcher'), | ||
captor = td.matchers.captor(); | ||
@@ -278,3 +327,3 @@ | ||
var td = require('testdouble'); | ||
var myTestDouble = td.create(); | ||
var myTestDouble = td.function(); | ||
@@ -303,3 +352,3 @@ td.explain(myTestDouble); /* | ||
Suported options are: | ||
Suported options are. Each should only ever be needed sparingly: | ||
@@ -310,3 +359,7 @@ * `ignoreExtraArgs` (default: **false**) a stubbing or verification will be satisfied | ||
still be considered satisfied. Use when you don't care about one, some, or any | ||
of the arguments a test double will receive. Use sparingly. | ||
of the arguments a test double will receive. | ||
* `times` (default: **undefined**) if set for a verification, will fail to verify | ||
unless a satisfactory invocation was made on the test double function `n` times. | ||
If set for a stubbing, will only return the stubbed value `n` times; afterward, | ||
the stubbing will be effectively deactivated. | ||
@@ -329,3 +382,3 @@ ## Setup notes | ||
``` javascript | ||
global.double = require('testdouble').create; | ||
global.double = require('testdouble').function; | ||
global.when = require('testdouble').when; | ||
@@ -332,0 +385,0 @@ global.verify = require('testdouble').verify; |
Sorry, the diff of this file is too big to display
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
536014
67
13769
380