New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

testdouble

Package Overview
Dependencies
Maintainers
2
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 1.9.1 to 1.10.0

examples/babel/lib/adder.js

17

docs/7-replacing-dependencies.md

@@ -23,7 +23,7 @@ # Replacing Real Dependencies with Test Doubles

* Plain objects are shallow-cloned and their top-level functions are replaced
with test double functions
* Constructor functions with at least one prototypal function defined will
_return_ a plain object of test double functions but will be _replaced by_ an
artificial constructor that, when instantiated, will delegate to those same
test double functions
with test double functions
* Constructor functions and ES classes with at least one prototypal function
defined will _return_ a plain object of test double functions but will be
_replaced by_ an artificial constructor that, when instantiated, will
delegate to those same test double functions

@@ -82,2 +82,9 @@ After the next call to `td.reset()` (which you should have in an `afterEach` hook

If you'd like an example of replacing ES classes that use the `export` keyword,
check out the [babel example
project](../examples/babel/test/lib/calculator-test.js). (Note that the test
itself must fall back to CommonJS-style `require` statements, since module
replacement requires the dependency be loaded after the replacements are
configured, which precludes the use of the static `import` statement.)
### How module replacement works

@@ -84,0 +91,0 @@

@@ -11,4 +11,5 @@ {

"mocha": "^3.0.2",
"semver": "^5.3.0",
"testdouble": "*"
}
}

@@ -1,6 +0,14 @@

import td from 'testdouble';
import td from 'testdouble'
import semver from 'semver'
global.context = describe;
global.td = td;
global.context = describe
global.td = td
afterEach(() => td.reset());
const nodeVersion = semver(process.version)
global.NODE_JS = {
AT_LEAST_0_11: nodeVersion.major > 0 || nodeVersion.minor >= 11,
AT_LEAST_6: nodeVersion.major >= 6
}
afterEach(() => td.reset())
// Generated by CoffeeScript 1.11.1
(function() {
var Brights;
module.exports = {

@@ -10,5 +12,15 @@ count: 4,

throw 'turnSignal';
}
},
brights: Brights = (function() {
function Brights() {}
Brights.prototype.beBright = function() {
throw 'too bright!';
};
return Brights;
})()
};
}).call(this);
// Generated by CoffeeScript 1.11.1
(function() {
var sourceDir;
var nodeVersion, sourceDir;

@@ -15,6 +15,11 @@ sourceDir = process.env.COVER != null ? process.env.COVER : 'src';

global.NODE_JS = true;
nodeVersion = require('semver')(process.version);
global.NODE_JS = {
AT_LEAST_0_11: nodeVersion.major > 0 || nodeVersion.minor >= 11,
AT_LEAST_6: nodeVersion.major >= 6
};
require('./general-helper');
}).call(this);

@@ -11,11 +11,2 @@ // Generated by CoffeeScript 1.11.1

},
dog: {
bark: function() {
return 'og bark';
},
woof: function() {
return 'og woof';
},
age: 18
},
thingConstructor: Thing = (function() {

@@ -87,2 +78,47 @@ function Thing() {}

});
describe('Replacing an ES6 constructor function', function() {
if (!(typeof NODE_JS !== "undefined" && NODE_JS !== null ? NODE_JS.AT_LEAST_6 : void 0)) {
return;
}
Given(function() {
return this.dependency.es6constructor = require('../../fixtures/es6class');
});
Given(function() {
return this.doubleBag = td.replace(this.dependency, 'es6constructor');
});
Given(function() {
return this.es6Thing = new this.dependency.es6constructor();
});
Then(function() {
return td.explain(this.doubleBag.foo).isTestDouble === true;
});
Then(function() {
return td.explain(this.doubleBag.bar).isTestDouble === true;
});
And(function() {
return this.doubleBag.foo === this.es6Thing.foo;
});
And(function() {
return this.doubleBag.bar === this.es6Thing.bar;
});
describe('the member td functions actually work', function() {
Given(function() {
return td.when(this.doubleBag.foo('cat')).thenReturn('dog');
});
return Then(function() {
return this.es6Thing.foo('cat') === 'dog';
});
});
return describe('reset restores it', function() {
When(function() {
return td.reset();
});
Then(function() {
return td.explain(new this.dependency.es6constructor().foo).isTestDouble === false;
});
return And(function() {
return new this.dependency.es6constructor().foo() === 'og foo';
});
});
});
describe('Replacing a method on an object instantiated with `new`', function() {

@@ -114,4 +150,24 @@ Given(function() {

describe('Replacing an object / function bag', function() {
Given(function() {
return this.horseClass = function() {};
});
Given(function() {
return this.horseClass.prototype.nay = function() {
return 'nay';
};
});
Given(function() {
return this.dependency.animals = {
bark: function() {
return 'og bark';
},
woof: function() {
return 'og woof';
},
age: 18,
horse: this.horseClass
};
});
When(function() {
return this.doubleBag = td.replace(this.dependency, 'dog');
return this.doubleBag = td.replace(this.dependency, 'animals');
});

@@ -125,10 +181,18 @@ Then(function() {

And(function() {
return this.doubleBag.bark === this.dependency.dog.bark;
return this.doubleBag.bark === this.dependency.animals.bark;
});
And(function() {
return this.doubleBag.woof === this.dependency.dog.woof;
return this.doubleBag.woof === this.dependency.animals.woof;
});
return And(function() {
And(function() {
return this.doubleBag.age === 18;
});
return describe('instantiable types work too', function() {
When(function() {
return td.when(this.doubleBag.horse.nay('hay')).thenReturn('no way');
});
return Then(function() {
return (new this.dependency.animals.horse()).nay('hay') === 'no way';
});
});
});

@@ -342,5 +406,16 @@ describe('Replacing a property that is not an object/function', function() {

});
return And(function() {
And(function() {
return this.car.lights.count === 4;
});
return describe('and classes on objects on funcs', function() {
if (!NODE_JS.AT_LEAST_0_11) {
return;
}
When(function() {
return td.when(this.lights.brights.beBright(1)).thenReturn('yow');
});
return Then(function() {
return (new this.car.lights.brights).beBright(1) === 'yow';
});
});
});

@@ -347,0 +422,0 @@ });

@@ -5,7 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
every: require('lodash/every'),
isEqual: require('lodash/isEqual'),
isFunction: require('lodash/isFunction')
};
_ = require('./util/lodash-wrap');

@@ -12,0 +8,0 @@ module.exports = function(expectedArgs, actualArgs, config) {

@@ -5,7 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
each: require('lodash/each'),
extend: require('lodash/extend'),
keys: require('lodash/keys')
};
_ = require('./util/lodash-wrap');

@@ -12,0 +8,0 @@ stringifyAnything = require('./stringify/anything');

@@ -5,5 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
reduce: require('lodash/reduce')
};
_ = require('./util/lodash-wrap');

@@ -10,0 +8,0 @@ store = require('./store');

@@ -6,5 +6,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
tap: require('lodash/tap')
};
_ = require('./util/lodash-wrap');

@@ -11,0 +9,0 @@ store = require('./store');

@@ -5,5 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
isFunction: require('lodash/isFunction')
};
_ = require('../util/lodash-wrap');

@@ -10,0 +8,0 @@ create = require('./create');

@@ -6,5 +6,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
isFunction: require('lodash/isFunction')
};
_ = require('../util/lodash-wrap');

@@ -11,0 +9,0 @@ stringifyArguments = require('../stringify/arguments');

@@ -5,13 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
every: require('lodash/every'),
includes: require('lodash/includes'),
isArray: require('lodash/isArray'),
isBoolean: require('lodash/isBoolean'),
isEqual: require('lodash/isEqual'),
isNumber: require('lodash/isNumber'),
isPlainObject: require('lodash/isPlainObject'),
isString: require('lodash/isString'),
some: require('lodash/some')
};
_ = require('../util/lodash-wrap');

@@ -18,0 +8,0 @@ log = require('../log');

// Generated by CoffeeScript 1.11.1
(function() {
var DEFAULT_OPTIONS, _, createTestDoubleObject, createTestDoubleViaProxy, createTestDoublesForFunctionBag, createTestDoublesForFunctionNames, createTestDoublesForPrototype, description, getAllPropertyNames, nameOf, tdFunction, withDefaults;
var DEFAULT_OPTIONS, _, cloneWithNonEnumerableProperties, createTestDoubleObject, createTestDoubleViaProxy, createTestDoublesForFunctionNames, createTestDoublesForPlainObject, createTestDoublesForPrototype, description, getAllPropertyNames, isConstructor, nameOf, tdFunction, withDefaults;
_ = {
extend: require('lodash/extend'),
functions: require('lodash/functions'),
includes: require('lodash/includes'),
isArray: require('lodash/isArray'),
isFunction: require('lodash/isFunction'),
isPlainObject: require('lodash/isPlainObject'),
isString: require('lodash/isString'),
reduce: require('lodash/reduce'),
tap: require('lodash/tap'),
union: require('lodash/union')
};
_ = require('./util/lodash-wrap');
cloneWithNonEnumerableProperties = require('./util/clone-with-non-enumerable-properties');
isConstructor = require('./replace/is-constructor');
tdFunction = require('./function');

@@ -33,6 +26,6 @@

createTestDoubleObject = function(nameOrType, config) {
if (_.isFunction(nameOrType)) {
if (isConstructor(nameOrType)) {
return createTestDoublesForPrototype(nameOrType);
} else if (_.isPlainObject(nameOrType)) {
return createTestDoublesForFunctionBag(nameOrType);
return createTestDoublesForPlainObject(nameOrType);
} else if (_.isArray(nameOrType)) {

@@ -64,7 +57,7 @@ return createTestDoublesForFunctionNames(nameOrType);

createTestDoublesForFunctionBag = function(bag) {
return _.reduce(_.functions(bag), function(memo, functionName) {
memo[functionName] = tdFunction("." + functionName);
createTestDoublesForPlainObject = function(obj) {
return _.reduce(_.functions(obj), function(memo, functionName) {
memo[functionName] = isConstructor(obj[functionName]) ? createTestDoublesForPrototype(obj[functionName]) : tdFunction("." + functionName);
return memo;
}, _.extend({}, bag));
}, cloneWithNonEnumerableProperties(obj));
};

@@ -71,0 +64,0 @@

// Generated by CoffeeScript 1.11.1
(function() {
var _, isConstructor, log, object, stringifyAnything, tdFunction, wrapWithConstructor;
var _, isConstructor, log, object, stringifyAnything, tdFunction;
_ = {
isFunction: require('lodash/isFunction'),
isPlainObject: require('lodash/isPlainObject')
};
_ = require('../util/lodash-wrap');

@@ -18,4 +15,2 @@ object = require('../object');

wrapWithConstructor = require('./wrap-with-constructor');
stringifyAnything = require('../stringify/anything');

@@ -22,0 +17,0 @@

@@ -5,5 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
isString: require('lodash/isString')
};
_ = require('../util/lodash-wrap');

@@ -10,0 +8,0 @@ replaceModule = require('./module');

@@ -5,6 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
functions: require('lodash/functions'),
some: require('lodash/some')
};
_ = require('../util/lodash-wrap');

@@ -15,5 +12,7 @@ module.exports = function(thing) {

}
return _.some(_.functions(thing.prototype));
return _.some(Object.getOwnPropertyNames(thing.prototype), function(property) {
return property !== 'constructor' && _.isFunction(thing.prototype[property]);
});
};
}).call(this);
// Generated by CoffeeScript 1.11.1
(function() {
var imitate, isConstructor, quibble, wrapIfNeeded, wrapWithConstructor;
var imitate, quibble, wrapIfNeeded;

@@ -9,6 +9,4 @@ quibble = require('quibble');

isConstructor = require('./is-constructor');
wrapIfNeeded = require('./wrap-if-needed');
wrapWithConstructor = require('./wrap-with-constructor');
quibble.ignoreCallsFromThisFile();

@@ -27,10 +25,2 @@

wrapIfNeeded = function(fakeThing, realThing) {
if (isConstructor(realThing)) {
return wrapWithConstructor(fakeThing);
} else {
return fakeThing;
}
};
}).call(this);
// Generated by CoffeeScript 1.11.1
(function() {
var _, imitate, isConstructor, log, reset, stringifyAnything, warnIfTypeMismatch, wrapIfNeeded, wrapWithConstructor;
var _, imitate, isConstructor, log, reset, stringifyAnything, warnIfTypeMismatch, wrapIfNeeded;
_ = {
capitalize: require('lodash/capitalize')
};
_ = require('../util/lodash-wrap');

@@ -13,3 +11,3 @@ imitate = require('./imitate');

wrapWithConstructor = require('./wrap-with-constructor');
wrapIfNeeded = require('./wrap-if-needed');

@@ -42,10 +40,2 @@ log = require('../log');

wrapIfNeeded = function(fakeThing, realThing) {
if (isConstructor(realThing)) {
return wrapWithConstructor(fakeThing);
} else {
return fakeThing;
}
};
warnIfTypeMismatch = function(property, fakeThing, realThing) {

@@ -52,0 +42,0 @@ var fakeType, realType;

@@ -5,5 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
each: require('lodash/each')
};
_ = require('../util/lodash-wrap');

@@ -10,0 +8,0 @@ module.exports = function(testDoubleFunctionBag) {

@@ -5,5 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
each: require('lodash/each')
};
_ = require('./util/lodash-wrap');

@@ -10,0 +8,0 @@ quibble = require('quibble');

@@ -5,6 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
filter: require('lodash/filter'),
tap: require('lodash/tap')
};
_ = require('../util/lodash-wrap');

@@ -11,0 +8,0 @@ store = require('./index');

@@ -5,6 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
find: require('lodash/find'),
tap: require('lodash/tap')
};
_ = require('../util/lodash-wrap');

@@ -11,0 +8,0 @@ EventEmitter = require('events').EventEmitter;

@@ -5,8 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
each: require('lodash/each'),
findLast: require('lodash/findLast'),
last: require('lodash/last'),
some: require('lodash/some')
};
_ = require('../util/lodash-wrap');

@@ -13,0 +8,0 @@ store = require('./index');

@@ -5,6 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
includes: require('lodash/includes'),
isString: require('lodash/isString')
};
_ = require('../util/lodash-wrap');

@@ -11,0 +8,0 @@ stringifyObject = require('stringify-object');

@@ -5,6 +5,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
find: require('lodash/find'),
reduce: require('lodash/reduce')
};
_ = require('./util/lodash-wrap');

@@ -11,0 +8,0 @@ store = require('./store');

// Generated by CoffeeScript 1.11.1
(function() {
module.exports = '1.9.1';
module.exports = '1.10.0';
}).call(this);

@@ -6,6 +6,3 @@ // Generated by CoffeeScript 1.11.1

_ = {
assign: require('lodash/assign'),
some: require('lodash/some')
};
_ = require('./util/lodash-wrap');

@@ -12,0 +9,0 @@ calls = require('./store/calls');

{
"name": "testdouble",
"version": "1.9.1",
"version": "1.10.0",
"description": "A minimal test double library for TDD with JavaScript",

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

"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",
"test:ci": "npm run clean && npm run compile && npm run test:all && npm run clean:dist",
"test:all": "npm test && testem ci && npm run test:example",
"test:ci": "npm run clean && npm run compile && npm run test:all && npm run clean:dist && echo \"All done!\"",
"test:debug": "npm test -- --debug-brk",

@@ -65,2 +65,4 @@ "version:write": "echo \"module.exports = '$npm_package_version'\" > src/version.coffee",

"mocha-istanbul": "arikon/mocha-istanbul",
"pryjs": "^1.0.3",
"semver": "^5.3.0",
"testem": "^0.9.4"

@@ -67,0 +69,0 @@ },

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

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

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