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 2.1.2 to 3.0.0

4

examples/node/lib/accelerometer.js
module.exports = {
read: function(){ throw 'unimplemented' }
read: function () {
throw new Error('unimplemented')
}
}

@@ -1,3 +0,5 @@

module.exports = function Brake(){}
module.exports = function Brake () {}
module.exports.prototype.engage = function(){ throw 'unimplemented' }
module.exports.prototype.engage = function () {
throw new Error('unimplemented')
}

@@ -1,13 +0,14 @@

accelerometer = require('./accelerometer')
gasPedal = require('./gas-pedal')
Brake = require('./brake')
copilot = require('./copilot')
var accelerometer = require('./accelerometer')
var gasPedal = require('./gas-pedal')
var Brake = require('./brake')
var copilot = require('./copilot')
module.exports = {
goSixty: function(){
var speed = accelerometer.read(),
brake = new Brake()
if(speed < 60) {
goSixty: function () {
var speed = accelerometer.read()
var brake = new Brake()
if (speed < 60) {
gasPedal(60 - speed)
} else if(speed > 60) {
} else if (speed > 60) {
brake.engage(speed - 60)

@@ -14,0 +15,0 @@ } else {

@@ -1,1 +0,3 @@

module.exports = function(){ throw 'unimplmented' }
module.exports = function () {
throw new Error('unimplemented')
}

@@ -5,12 +5,18 @@ {

"scripts": {
"test": "mocha -R spec --recursive test/helper.js test/lib/",
"test:unit": "teenytest",
"test:style": "standard",
"test": "yarn run test:unit && yarn run test:style",
"test:debug": "yarn test -- --debug-brk"
},
"devDependencies": {
"chai": "^3.3.0",
"core-assert": "^0.2.1",
"elasticsearch": "^12.1.3",
"is-number": "^3.0.0",
"mocha": "^2.3.3",
"standard": "^10.0.2",
"teenytest": "^5.0.2",
"testdouble": "*"
},
"standard": {
"globals": ["td", "assert"]
}
}

@@ -1,7 +0,8 @@

global.expect = require('chai').expect;
global.context = describe;
global.td = require('testdouble');
global.td = require('testdouble')
global.assert = require('core-assert')
afterEach(function(){
td.reset();
});
module.exports = {
afterEach: function () {
td.reset()
}
}

@@ -1,47 +0,35 @@

describe('Car', function(){
var subject, gasPedal, accelerometer, Brake
beforeEach(function(){
gasPedal = td.replace('../../lib/gas-pedal') //<-- a plain ol' function
accelerometer = td.replace('../../lib/accelerometer') //<-- an obj of functions
Brake = td.replace('../../lib/brake') //<-- a constructor function
copilot = td.replace('../../lib/copilot', function() { return 'HIGHFIVE'}) //<-- a manual override
var subject, gasPedal, accelerometer, Brake
module.exports = {
beforeEach: function () {
gasPedal = td.replace('../../lib/gas-pedal') // <-- a plain ol' function
accelerometer = td.replace('../../lib/accelerometer') // <-- an obj of functions
Brake = td.replace('../../lib/brake') // <-- a constructor function
td.replace('../../lib/copilot', function () { return 'HIGHFIVE' }) // <-- a manual override
subject = require('../../lib/car')
})
},
describe('.goSixty', function(){
describe('not yet going 60', function(){
beforeEach(function(){
td.when(accelerometer.read()).thenReturn(55)
'.goSixty': {
'not yet going 60 -> pushes the pedal down 5 units': function () {
td.when(accelerometer.read()).thenReturn(55)
subject.goSixty()
})
subject.goSixty()
it('pushes the pedal down 5 units', function(){
td.verify(gasPedal(5))
})
})
td.verify(gasPedal(5))
},
describe('going over 60', function(){
beforeEach(function(){
td.when(accelerometer.read()).thenReturn(62)
'going over 60 -> engages the brake for 2 units': function () {
td.when(accelerometer.read()).thenReturn(62)
subject.goSixty()
})
subject.goSixty()
it('engages the brake for 2 units', function(){
td.verify(Brake.prototype.engage(2))
})
})
td.verify(Brake.prototype.engage(2))
},
describe('going exactly 60', function(){
var result;
beforeEach(function(){
result = subject.goSixty()
})
'going exactly 60 invokes the copilot for some weird reason': function () {
var result = subject.goSixty()
it('invokes the copilot for some weird reason', function(){
expect(result).to.equal('HIGHFIVE')
})
})
})
})
assert.equal(result, 'HIGHFIVE')
}
}
}

@@ -1,11 +0,9 @@

describe('elastic-thing', function () {
it('is quite elastic', function () {
var elasticsearch = td.replace('elasticsearch')
var subject = require('../../lib/elastic-thing')
td.when(elasticsearch.Client()).thenReturn('pants')
module.exports = function elasticThingIsQuiteElastic () {
var elasticsearch = td.replace('elasticsearch')
var subject = require('../../lib/elastic-thing')
td.when(elasticsearch.Client()).thenReturn('pants')
var result = subject()
var result = subject()
expect(result).to.eq('pants')
})
})
assert.equal(result, 'pants')
}

@@ -1,3 +0,3 @@

describe('numbers-only', function () {
it('replaces modules ok', function () {
module.exports = {
'replaces numbers okay': function () {
var isNumber = td.replace('is-number')

@@ -9,4 +9,4 @@ var numbersOnly = require('../../lib/numbers-only')

expect(result).to.eq(true)
})
})
assert.equal(result, true)
}
}

@@ -23,2 +23,5 @@ export type TestDouble = Function;

// When passed class or constuctor function name as string value
export function object<T>(object: string): DoubledObject<T>;
// When passed general object

@@ -25,0 +28,0 @@ export function object<T>(object: T): DoubledObject<T>;

@@ -22,4 +22,5 @@ 'use strict';

var DEFAULTS = {
extendWhenReplacingConstructors: false,
ignoreWarnings: false,
promiseConstructor: global.Promise,
ignoreWarnings: false,
suppressErrors: false

@@ -26,0 +27,0 @@ };

@@ -19,2 +19,10 @@ 'use strict';

var _config = require('./config');
var _config2 = _interopRequireDefault(_config);
var _copyProperties = require('./util/copy-properties');
var _copyProperties2 = _interopRequireDefault(_copyProperties);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -33,19 +41,7 @@

var fakeConstructorFromType = function fakeConstructorFromType(type) {
var name = type.name || '';
var fauxConstructor = (0, _function2.default)(name + ' constructor');
return _lodashWrap2.default.tap(createFakeType(type), function (fakeType) {
var name = type.name || '';
(0, _copyProperties2.default)(type, fakeType);
(0, _copyProperties2.default)(type.prototype, fakeType.prototype);
return _lodashWrap2.default.tap(function (_type) {
_inherits(TestDoubleConstructor, _type);
function TestDoubleConstructor() {
_classCallCheck(this, TestDoubleConstructor);
var _this = _possibleConstructorReturn(this, (TestDoubleConstructor.__proto__ || Object.getPrototypeOf(TestDoubleConstructor)).apply(this, arguments));
fauxConstructor.apply(undefined, arguments);
return _this;
}
return TestDoubleConstructor;
}(type), function (fakeType) {
// Override "static" functions with instance test doubles

@@ -65,2 +61,29 @@ _lodashWrap2.default.each(_lodashWrap2.default.functions(type), function (funcName) {

var createFakeType = function createFakeType(type) {
var fauxConstructor = (0, _function2.default)((type.name || 'anonymous') + ' constructor');
if ((0, _config2.default)().extendWhenReplacingConstructors) {
return function (_type) {
_inherits(TestDoubleConstructorExtendingRealType, _type);
function TestDoubleConstructorExtendingRealType() {
_classCallCheck(this, TestDoubleConstructorExtendingRealType);
var _this = _possibleConstructorReturn(this, (TestDoubleConstructorExtendingRealType.__proto__ || Object.getPrototypeOf(TestDoubleConstructorExtendingRealType)).apply(this, arguments));
fauxConstructor.apply(undefined, arguments);
return _this;
}
return TestDoubleConstructorExtendingRealType;
}(type);
} else {
return function TestDoubleConstructor() {
_classCallCheck(this, TestDoubleConstructor);
fauxConstructor.apply(undefined, arguments);
};
}
};
var fakeConstructorFromNames = function fakeConstructorFromNames(funcNames) {

@@ -67,0 +90,0 @@ return _lodashWrap2.default.tap(function TestDoubleConstructor() {

'use strict';
var _callback = require('./matchers/callback');
var _function = require('./function');
var _callback2 = _interopRequireDefault(_callback);
var _function2 = _interopRequireDefault(_function);
var _config = require('./config');
var _object = require('./object');
var _config2 = _interopRequireDefault(_config);
var _object2 = _interopRequireDefault(_object);

@@ -15,6 +15,10 @@ var _constructor = require('./constructor');

var _explain = require('./explain');
var _when = require('./when');
var _explain2 = _interopRequireDefault(_explain);
var _when2 = _interopRequireDefault(_when);
var _verify = require('./verify');
var _verify2 = _interopRequireDefault(_verify);
var _matchers = require('./matchers');

@@ -24,6 +28,2 @@

var _object = require('./object');
var _object2 = _interopRequireDefault(_object);
var _replace = require('./replace');

@@ -33,2 +33,6 @@

var _explain = require('./explain');
var _explain2 = _interopRequireDefault(_explain);
var _reset = require('./reset');

@@ -38,9 +42,9 @@

var _function = require('./function');
var _config = require('./config');
var _function2 = _interopRequireDefault(_function);
var _config2 = _interopRequireDefault(_config);
var _verify = require('./verify');
var _callback = require('./matchers/callback');
var _verify2 = _interopRequireDefault(_verify);
var _callback2 = _interopRequireDefault(_callback);

@@ -51,6 +55,2 @@ var _version = require('./version');

var _when = require('./when');
var _when2 = _interopRequireDefault(_when);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -57,0 +57,0 @@

@@ -6,2 +6,2 @@ 'use strict';

});
exports.default = '2.1.2';
exports.default = '3.0.0';
{
"name": "testdouble",
"version": "2.1.2",
"version": "3.0.0",
"description": "A minimal test double library for TDD with JavaScript",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/testdouble/testdouble.js",

@@ -6,4 +6,5 @@ import _ from './util/lodash-wrap'

const DEFAULTS = {
extendWhenReplacingConstructors: false,
ignoreWarnings: false,
promiseConstructor: global.Promise,
ignoreWarnings: false,
suppressErrors: false

@@ -10,0 +11,0 @@ }

import _ from './util/lodash-wrap'
import getAllCustomPrototypalFunctionNames from './util/get-all-custom-prototypal-function-names'
import tdFunction from './function'
import config from './config'
import copyProperties from './util/copy-properties'

@@ -10,12 +12,8 @@ export default (typeOrNames) =>

var fakeConstructorFromType = (type) => {
const name = type.name || ''
const fauxConstructor = tdFunction(`${name} constructor`)
var fakeConstructorFromType = (type) =>
_.tap(createFakeType(type), (fakeType) => {
const name = type.name || ''
copyProperties(type, fakeType)
copyProperties(type.prototype, fakeType.prototype)
return _.tap(class TestDoubleConstructor extends type {
constructor () {
super(...arguments)
fauxConstructor(...arguments)
}
}, (fakeType) => {
// Override "static" functions with instance test doubles

@@ -33,2 +31,20 @@ _.each(_.functions(type), funcName => {

})
var createFakeType = (type) => {
const fauxConstructor = tdFunction(`${type.name || 'anonymous'} constructor`)
if (config().extendWhenReplacingConstructors) {
return class TestDoubleConstructorExtendingRealType extends type {
constructor () {
super(...arguments)
fauxConstructor(...arguments)
}
}
} else {
return class TestDoubleConstructor {
constructor () {
fauxConstructor(...arguments)
}
}
}
}

@@ -35,0 +51,0 @@

@@ -1,13 +0,13 @@

import callback from './matchers/callback'
import config from './config'
import tdFunction from './function'
import object from './object'
import constructor from './constructor'
import explain from './explain'
import when from './when'
import verify from './verify'
import matchers from './matchers'
import object from './object'
import replace from './replace'
import explain from './explain'
import reset from './reset'
import tdFunction from './function'
import verify from './verify'
import config from './config'
import callback from './matchers/callback'
import version from './version'
import when from './when'

@@ -14,0 +14,0 @@ module.exports = {

@@ -1,1 +0,1 @@

export default '2.1.2'
export default '3.0.0'
describe('td.config', () => {
it('sets some ok defaults', () => {
expect(td.config()).to.deep.equal({
extendWhenReplacingConstructors: false,
ignoreWarnings: false,
promiseConstructor: global.Promise,
ignoreWarnings: false,
suppressErrors: false

@@ -24,5 +25,5 @@ })

'Error: testdouble.js - td.config - "wat" is not a valid configuration ' +
'key (valid keys are: ["promiseConstructor", "ignoreWarnings", ' +
'"suppressErrors"])')
'key (valid keys are: [\n "extendWhenReplacingConstructors",\n "ignoreWarnings",' +
'\n "promiseConstructor",\n "suppressErrors"\n])')
})
})

@@ -20,2 +20,6 @@ import * as td from "../../../";

class Bear { constructor() {}; sleep() {}; };
const bear = td.object<Bear>("Bear");
td.when(bear.sleep()).thenReturn("zzz");
td.replace({}, "prop");

@@ -22,0 +26,0 @@ td.replace({}, "prop", 42);

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 too big to display

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