Comparing version 0.0.9 to 0.1.0
var mod = require('module'); | ||
var partialMock = require('./partialMock/simple/newPartialMock')(mod._load); | ||
var originalLoad = mod._load; | ||
mod._load = loadHook; | ||
function loadHook(request,parent,isMain) { | ||
return partialMock(request,parent,isMain); | ||
} | ||
function expect(request) { | ||
return partialMock.expect(request).expectAnything().expectAnything(); | ||
return mod._requireMock.expect(request).expectAnything().expectAnything(); | ||
} | ||
loadHook._aClearMocks = function(){ | ||
mod._load = originalLoad; | ||
if (mod._load._aClearMocks) | ||
mod._load._aClearMocks(); | ||
}; | ||
if(!mod._requireMock) { | ||
expect.clear = loadHook._aClearMocks; | ||
mod._requireMock = require('./partialMock/simple/newPartialMock')(mod._load); | ||
var originalLoad = mod._load; | ||
mod._load = loadHook; | ||
function loadHook(request,parent,isMain) { | ||
return mod._requireMock(request,parent,isMain); | ||
} | ||
} | ||
expect.clear = mod._requireMock.clear; | ||
module.exports = expect; |
@@ -51,4 +51,7 @@ var sut = require('../expectRequire'); | ||
sut.clear(); | ||
var returned = require('./foo'); | ||
sut('./foo').return(fooFake); | ||
var returnedSecond = require('./foo'); | ||
var returned = require('./foo'); | ||
@@ -59,4 +62,8 @@ test('it should execute returns real foo', function(){ | ||
test('it should execute returns fake foo second time', function(){ | ||
assert.equal(fooFake,returnedSecond); | ||
}); | ||
})(); | ||
})(); |
{ | ||
"name": "a_mock", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "title": "a_mock", |
@@ -115,2 +115,6 @@ function create(originalFunc) { | ||
mock.clear = function() { | ||
mockArray = []; | ||
}; | ||
return mock; | ||
@@ -117,0 +121,0 @@ } |
@@ -67,2 +67,28 @@ var newSut = require('../newPartialMock'); | ||
(function() { | ||
console.log('expect return after clear'); | ||
var sut = newSut(original); | ||
sut.expect().return(foo); | ||
sut.expect().return(foo); | ||
var firstReturned = sut(); | ||
sut.clear(); | ||
var secondReturned = sut(); | ||
sut.expect().return(foo); | ||
var thirdReturned = sut(); | ||
test('it should execute returns foo first time', function(){ | ||
assert.equal(foo,firstReturned); | ||
}); | ||
test('it should execute returns original second time', function(){ | ||
assert.equal(originalReturnValue,secondReturned); | ||
}); | ||
test('it should execute returns foo third time', function(){ | ||
assert.equal(foo,thirdReturned); | ||
}); | ||
})(); | ||
(function() { | ||
console.log('expect return foo then baz'); | ||
@@ -69,0 +95,0 @@ var sut = newSut(original); |
119445
3861