testdouble
Advanced tools
Comparing version 1.6.1 to 1.6.2
# Change Log | ||
## [v1.6.2](https://github.com/testdouble/testdouble.js/tree/v1.6.2) (2016-09-18) | ||
[Full Changelog](https://github.com/testdouble/testdouble.js/compare/v1.6.1...v1.6.2) | ||
**Closed issues:** | ||
- Add support for concurrent test runners \(ava\)? [\#131](https://github.com/testdouble/testdouble.js/issues/131) | ||
- Async use of verify results in timeout [\#129](https://github.com/testdouble/testdouble.js/issues/129) | ||
**Merged pull requests:** | ||
- Should methods on super types be stubbed in td.object? [\#130](https://github.com/testdouble/testdouble.js/pull/130) ([paultyng](https://github.com/paultyng)) | ||
## [v1.6.1](https://github.com/testdouble/testdouble.js/tree/v1.6.1) (2016-08-31) | ||
@@ -4,0 +16,0 @@ [Full Changelog](https://github.com/testdouble/testdouble.js/compare/v1.6.0...v1.6.1) |
@@ -31,3 +31,3 @@ # Creating Test Doubles | ||
* Pass `td.object()` a real **constructor** with functions defined on its prototype object or a **plain JavaScript object** which contains functions as properties. testdouble.js will mirror either of these by replacing all the functions it detects. If you practice this style, it means part of your test-driven workflow will require you to define those constructors and objects as you go in your production code. This is a great way to take advantage of the TDD workflow to implement a skeleton of your object graph as you work, all-the-while keeping the contracts between your subject and its dependencies explicit enough to catch failures when you change the contract between the [subject](https://github.com/testdouble/contributing-tests/wiki/Subject) and its dependencies (i.e. if you change the name of a dependency's function, the test double function would disappear and break the caller's test) | ||
* Pass `td.object()` a real **constructor** with functions defined on its prototype object, an **ES2015 class**, or a **plain JavaScript object** which contains functions as properties. testdouble.js will mirror either of these by replacing all the functions it detects, including those inherited from its prototype chain. If you practice this style, it means part of your test-driven workflow will require you to define those constructors and objects as you go in your production code. This is a great way to take advantage of the TDD workflow to implement a skeleton of your object graph as you work, all-the-while keeping the contracts between your subject and its dependencies explicit enough to catch failures when you change the contract between the [subject](https://github.com/testdouble/contributing-tests/wiki/Subject) and its dependencies (i.e. if you change the name of a dependency's function, the test double function would disappear and break the caller's test). | ||
* Pass `td.object()` an **array of function names** or (if using a runtime that implements [ES2015 Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)) a **name for the object**. This style makes prototyping interactions easier because it doesn't require the author to define production-scope functions of dependencies while authoring the caller's test. Conversely, it runs the risk of "fantasy green" tests that continue passing even if a dependency's functions change in the future | ||
@@ -34,0 +34,0 @@ |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
describe('td.object', function() { | ||
describe('making a test double object based on a Prototypal thing', function() { | ||
describe.only('making a test double object based on a Prototypal thing', function() { | ||
Given(function() { | ||
@@ -14,2 +17,4 @@ var Thing; | ||
Thing.prototype.notAFunc = 11; | ||
return Thing; | ||
@@ -31,5 +36,8 @@ | ||
}); | ||
return And(function() { | ||
And(function() { | ||
return this.testDouble.foo.toString() === '[test double for "Thing#foo"]'; | ||
}); | ||
return And(function() { | ||
return this.testDouble.notAFunc === 11; | ||
}); | ||
}); | ||
@@ -81,2 +89,45 @@ describe('making a test double based on a plain object funcbag', function() { | ||
}); | ||
describe('making a test double on a subtype', function() { | ||
Given(function() { | ||
var SuperType; | ||
return this.someSuperType = SuperType = (function() { | ||
function SuperType() {} | ||
SuperType.prototype.foo = function() {}; | ||
return SuperType; | ||
})(); | ||
}); | ||
Given(function() { | ||
var SubType; | ||
return this.someSubType = SubType = (function(superClass) { | ||
extend(SubType, superClass); | ||
function SubType() { | ||
return SubType.__super__.constructor.apply(this, arguments); | ||
} | ||
SubType.prototype.bar = function() {}; | ||
return SubType; | ||
})(this.someSuperType); | ||
}); | ||
Given(function() { | ||
return this.testDouble = td.object(this.someSubType); | ||
}); | ||
When(function() { | ||
return td.when(this.testDouble.foo()).thenReturn('yay'); | ||
}); | ||
When(function() { | ||
return td.when(this.testDouble.bar()).thenReturn('yay'); | ||
}); | ||
Then(function() { | ||
return this.testDouble.foo() === 'yay'; | ||
}); | ||
return Then(function() { | ||
return this.testDouble.bar() === 'yay'; | ||
}); | ||
}); | ||
if (global.Proxy != null) { | ||
@@ -83,0 +134,0 @@ return describe('creating a proxy object (ES2015; only supported in FF + Edge atm)', function() { |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
var DEFAULT_OPTIONS, _, createTestDoubleObject, createTestDoubleViaProxy, createTestDoublesForFunctionBag, createTestDoublesForFunctionNames, createTestDoublesForPrototype, description, nameOf, tdFunction, withDefaults; | ||
var DEFAULT_OPTIONS, _, createTestDoubleObject, createTestDoubleViaProxy, createTestDoublesForFunctionBag, createTestDoublesForFunctionNames, createTestDoublesForPrototype, description, getAllPropertyNames, nameOf, tdFunction, withDefaults; | ||
@@ -33,4 +33,16 @@ _ = require('lodash'); | ||
getAllPropertyNames = function(type) { | ||
var props; | ||
props = []; | ||
while (true) { | ||
props = _.union(props, Object.getOwnPropertyNames(type)); | ||
if (!(type = Object.getPrototypeOf(type))) { | ||
break; | ||
} | ||
} | ||
return props; | ||
}; | ||
createTestDoublesForPrototype = function(type) { | ||
return _.reduce(Object.getOwnPropertyNames(type.prototype), function(memo, name) { | ||
return _.reduce(getAllPropertyNames(type.prototype), function(memo, name) { | ||
memo[name] = _.isFunction(type.prototype[name]) ? tdFunction((nameOf(type)) + "#" + name) : type.prototype[name]; | ||
@@ -37,0 +49,0 @@ return memo; |
// Generated by CoffeeScript 1.10.0 | ||
(function() { | ||
module.exports = '1.6.1'; | ||
module.exports = '1.6.2'; | ||
}).call(this); |
{ | ||
"name": "testdouble", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "A minimal test double library for TDD with JavaScript", | ||
@@ -32,3 +32,4 @@ "homepage": "https://github.com/testdouble/testdouble.js", | ||
"test:example:lineman": "cd examples/lineman && npm i && npm test && cd ../..", | ||
"test:example": "npm run test:example:node && npm run test:example:lineman && npm run test:example:webpack", | ||
"test:example:babel": "cd examples/babel && npm i && npm test && cd ../..", | ||
"test:example": "npm run test:example:node && npm run test:example:lineman && npm run test:example:webpack && npm run test:example:babel", | ||
"test:all": "npm run test --testdouble:mocha_reporter=tap && testem ci && npm run test:example", | ||
@@ -35,0 +36,0 @@ "test:ci": "npm run clean && npm run compile && npm run test:all && npm run clean:dist", |
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
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
807287
166
17873