Comparing version 0.1.0 to 0.2.0
@@ -28,6 +28,7 @@ /** | ||
Mocker.prototype.withAsyncStub = function (funcName, expectedCallbackArgs) { | ||
Mocker.prototype.withAsyncStub = function (funcName, expectedCallbackArgs, delay) { | ||
this.__mockedAsyncFuncs.push({ | ||
name: funcName, | ||
expectedCbArgs: expectedCallbackArgs | ||
expectedCbArgs: expectedCallbackArgs, | ||
delay: delay | ||
}); | ||
@@ -57,3 +58,9 @@ return this; | ||
var cbFunc = arguments[argCount]; | ||
return cbFunc.apply(undefined, x.expectedCbArgs); | ||
if (x.delay != null) { | ||
setTimeout(function () { | ||
return cbFunc.apply(undefined, x.expectedCbArgs); | ||
}, x.delay) | ||
}else | ||
return cbFunc.apply(undefined, x.expectedCbArgs); | ||
}; | ||
@@ -60,0 +67,0 @@ }); |
{ | ||
"name": "mini-mock", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "An ultra-lightweight mocking framework for Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,2 +20,6 @@ /** | ||
this.__motorWithDelay = mocker.mock(Motor.prototype) | ||
.withAsyncStub('start', [null, 250], 1500) // callback args are [null, 250] | ||
.create(); | ||
this.__motorFactory = mocker.mock(MotorFactory.prototype) | ||
@@ -25,2 +29,6 @@ .withSyncStub('getMotor', this.__motor) | ||
this.__motorFactoryWithDelay = mocker.mock(MotorFactory.prototype) | ||
.withSyncStub('getMotor', this.__motorWithDelay) | ||
.create(); | ||
done(); | ||
@@ -44,2 +52,23 @@ }); | ||
it('mock asynchronous function with delay returns correct result', function (done) { | ||
var robot = new Robot(this.__motorFactoryWithDelay); | ||
var start = Date.now(); | ||
robot.walk(function (e, result) { | ||
if (e) | ||
return done(e); | ||
var end = Date.now(); | ||
var timeDiff = end - start; | ||
expect(timeDiff).to.be.greaterThan(1000); | ||
expect(result).to.equal(250); | ||
done(); | ||
}) | ||
}); | ||
it('mock synchronous function returns correct result', function (done) { | ||
@@ -46,0 +75,0 @@ |
11556
178