Comparing version 0.0.11 to 0.0.13
152
bond.js
@@ -1,9 +0,10 @@ | ||
// Generated by CoffeeScript 1.3.3 | ||
(function() { | ||
var allStubs, arrayEqual, bond, createAnonymousSpy, createReturnSpy, createThroughSpy, enhanceSpy, registerCleanupHook, | ||
__slice = [].slice; | ||
createThroughSpy = function(getValue, bondApi) { | ||
// Generated by CoffeeScript 2.0.0-beta4 | ||
void function () { | ||
var allStubs, arrayEqual, bond, createAnonymousSpy, createReturnSpy, createThroughSpy, enhanceSpy, isFunction, nextTick, registerCleanupHook; | ||
isFunction = function (obj) { | ||
return typeof obj === 'function'; | ||
}; | ||
createThroughSpy = function (getValue, bondApi) { | ||
var spy; | ||
spy = function() { | ||
spy = function () { | ||
var args, isConstructor, result; | ||
@@ -15,5 +16,4 @@ args = Array.prototype.slice.call(arguments); | ||
isConstructor = this instanceof arguments.callee; | ||
if (isConstructor) { | ||
if (isConstructor) | ||
return this; | ||
} | ||
return result; | ||
@@ -23,6 +23,5 @@ }; | ||
}; | ||
createReturnSpy = function(getValue, bondApi) { | ||
createReturnSpy = function (getValue, bondApi) { | ||
var spy; | ||
spy = function() { | ||
spy = function () { | ||
var args; | ||
@@ -36,7 +35,6 @@ args = Array.prototype.slice.call(arguments); | ||
}; | ||
createAnonymousSpy = function() { | ||
createAnonymousSpy = function () { | ||
var returnValue, spy; | ||
returnValue = null; | ||
spy = function() { | ||
spy = function () { | ||
var args; | ||
@@ -49,3 +47,3 @@ args = Array.prototype.slice.call(arguments); | ||
enhanceSpy(spy); | ||
spy["return"] = function(newReturnValue) { | ||
spy['return'] = function (newReturnValue) { | ||
returnValue = newReturnValue; | ||
@@ -56,18 +54,16 @@ return spy; | ||
}; | ||
enhanceSpy = function(spy, original, bondApi) { | ||
enhanceSpy = function (spy, original, bondApi) { | ||
var k, v; | ||
spy.prototype = original != null ? original.prototype : void 0; | ||
spy.prototype = null != original ? original.prototype : void 0; | ||
spy.called = 0; | ||
spy.calledArgs = []; | ||
spy.calledWith = function() { | ||
var args, lastArgs; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
if (!spy.called) { | ||
spy.calledWith = function (args) { | ||
var lastArgs; | ||
args = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; | ||
if (!spy.called) | ||
return false; | ||
} | ||
lastArgs = spy.calledArgs[spy.called - 1]; | ||
return arrayEqual(args, lastArgs); | ||
}; | ||
if (bondApi) { | ||
if (bondApi) | ||
for (k in bondApi) { | ||
@@ -77,29 +73,34 @@ v = bondApi[k]; | ||
} | ||
} | ||
return spy; | ||
}; | ||
arrayEqual = function(A, B) { | ||
var a, b, i, _i, _len; | ||
for (i = _i = 0, _len = A.length; _i < _len; i = ++_i) { | ||
a = A[i]; | ||
arrayEqual = function (A, B) { | ||
var a, b, i; | ||
for (var i$ = 0, length$ = A.length; i$ < length$; ++i$) { | ||
a = A[i$]; | ||
i = i$; | ||
b = B[i]; | ||
if (a !== b) { | ||
if (a !== b) | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
nextTick = function () { | ||
if (isFunction('undefined' !== typeof process && null != process ? process.nextTick : void 0)) | ||
return process.nextTick; | ||
if ('undefined' !== typeof setImmediate && null != setImmediate && isFunction(setImmediate)) | ||
return setImmediate; | ||
return function (fn) { | ||
return setTimeout(fn, 0); | ||
}; | ||
}(); | ||
allStubs = []; | ||
registerCleanupHook = function() { | ||
var after, _ref, _ref1; | ||
after = (_ref = (_ref1 = typeof afterEach !== "undefined" && afterEach !== null ? afterEach : testDone) != null ? _ref1 : this.cleanup) != null ? _ref : function() { | ||
(registerCleanupHook = function () { | ||
var after; | ||
after = 'undefined' !== typeof afterEach && null != afterEach ? afterEach : 'undefined' !== typeof testDone && null != testDone ? testDone : null != this.cleanup ? this.cleanup : function () { | ||
throw new Error('bond.cleanup must be specified if your test runner does not use afterEach or testDone'); | ||
}; | ||
return after(function() { | ||
var stubRestore, _i, _len; | ||
for (_i = 0, _len = allStubs.length; _i < _len; _i++) { | ||
stubRestore = allStubs[_i]; | ||
return after(function () { | ||
var stubRestore; | ||
for (var i$ = 0, length$ = allStubs.length; i$ < length$; ++i$) { | ||
stubRestore = allStubs[i$]; | ||
stubRestore(); | ||
@@ -109,30 +110,25 @@ } | ||
}); | ||
}; | ||
registerCleanupHook(); | ||
bond = function(obj, property) { | ||
var previous, registerRestore, restore, returnMethod, through, to; | ||
if (arguments.length === 0) { | ||
})(); | ||
bond = function (obj, property) { | ||
var asyncReturn, previous, registerRestore, restore, returnMethod, through, to; | ||
if (arguments.length === 0) | ||
return createAnonymousSpy(); | ||
} | ||
previous = obj[property]; | ||
if (!(previous != null)) { | ||
throw new Error("Could not find property " + property + "."); | ||
} | ||
registerRestore = function() { | ||
registerRestore = function () { | ||
return allStubs.push(restore); | ||
}; | ||
restore = function() { | ||
restore = function () { | ||
return obj[property] = previous; | ||
}; | ||
to = function(newValue) { | ||
to = function (newValue) { | ||
registerRestore(); | ||
if (isFunction(newValue)) | ||
newValue = createThroughSpy(newValue, this); | ||
obj[property] = newValue; | ||
return obj[property]; | ||
}; | ||
returnMethod = function(returnValue) { | ||
returnMethod = function (returnValue) { | ||
var returnValueFn; | ||
registerRestore(); | ||
returnValueFn = function() { | ||
returnValueFn = function () { | ||
return returnValue; | ||
@@ -143,3 +139,20 @@ }; | ||
}; | ||
through = function() { | ||
asyncReturn = function (returnValues) { | ||
returnValues = 1 <= arguments.length ? [].slice.call(arguments, 0) : []; | ||
return to(function (callback) { | ||
var args, numArgs$; | ||
if ((numArgs$ = arguments.length) > 1) { | ||
args = [].slice.call(arguments, 0, numArgs$ - 1); | ||
callback = arguments[numArgs$ - 1]; | ||
} else { | ||
args = []; | ||
} | ||
if (!isFunction(callback)) | ||
throw new Error('asyncReturn expects last argument to be a function'); | ||
return nextTick(function () { | ||
return callback.apply(null, [].slice.call(returnValues).concat()); | ||
}); | ||
}); | ||
}; | ||
through = function () { | ||
obj[property] = createThroughSpy(previous, this); | ||
@@ -149,19 +162,14 @@ return obj[property]; | ||
return { | ||
'to': to, | ||
to: to, | ||
'return': returnMethod, | ||
'through': through, | ||
'restore': restore | ||
asyncReturn: asyncReturn, | ||
through: through, | ||
restore: restore | ||
}; | ||
}; | ||
bond.version = '0.0.11'; | ||
if (typeof window !== "undefined" && window !== null) { | ||
bond.version = '0.0.13'; | ||
if ('undefined' !== typeof window && null != window) | ||
window.bond = bond; | ||
} | ||
if (typeof module !== "undefined" && module !== null) { | ||
if ('undefined' !== typeof module && null != module ? module.exports : void 0) | ||
module.exports = bond; | ||
} | ||
}).call(this); | ||
}.call(this); |
{ | ||
"name": "bondjs", | ||
"version": "0.0.11", | ||
"version": "0.0.13", | ||
"description": "simple js stub/spy library", | ||
"main": "bond.js", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script test.coffee", | ||
"prepublish": "./node_modules/coffee-script/bin/coffee -c bond.coffee" | ||
}, | ||
"author": "Sean Massa <endangeredmassa@gmail.com>", | ||
"devDependencies": { | ||
"mocha": "~1.6.0", | ||
"coffee-script": "~1.3.3" | ||
"coffee-script-redux" : "~2.0.0" | ||
} | ||
} |
@@ -19,2 +19,4 @@ bond: the simple stub/spy javascript library | ||
`bond#asyncReturn(values...)` replaces the value with a spy that calls the last argument passed to the function with the provided values | ||
`bond#through()` replaces the value with a spy, but allows it to return its normal value | ||
@@ -21,0 +23,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
16263
7
166
59
1