nodemock
Advanced tools
Comparing version 0.2.3beta to 0.2.4beta
@@ -42,4 +42,6 @@ /** | ||
if(deepObjectCheck(entry.args, args)) { | ||
entry.executed ++; | ||
return entry; | ||
} | ||
//increasing executed numbers for that entry | ||
} | ||
@@ -84,2 +86,8 @@ return false; | ||
this.times = function(expected) { | ||
var entry = entries[currentMockFunction][entries[currentMockFunction].length - 1]; | ||
entry.expectedExecutions = expected; | ||
return this; | ||
}; | ||
this.returns = function(value) { | ||
@@ -107,2 +115,20 @@ var entry = entries[currentMockFunction][entries[currentMockFunction].length - 1]; | ||
this.assert = function() { | ||
var success = true; | ||
for(var method in entries) { | ||
var entriesForMethod = entries[method]; | ||
entriesForMethod.forEach(function(entry) { | ||
if(entry.executed != entry.expectedExecutions) { | ||
success = false; | ||
console.error( | ||
"method call for: '" + method + "()' with params: " + getParamString(entry.args) + " executed " + | ||
entry.executed + " times. (but excepted " + entry.expectedExecutions + " times)"); | ||
} | ||
}); | ||
} | ||
return success; | ||
}; | ||
//Assign the mocking function | ||
@@ -125,3 +151,5 @@ this.mock = function(method) { | ||
callbackParams: null, | ||
returns: undefined | ||
returns: undefined, | ||
executed: 0, | ||
expectedExecutions: 1 | ||
}); | ||
@@ -163,2 +191,19 @@ | ||
function getParamString(params) { | ||
var paramString = "("; | ||
for(var index in params) { | ||
var param = params[index]; | ||
if(param instanceof Function) { | ||
paramString += "function() {}, "; | ||
} else if(param instanceof RegExp) { | ||
paramString += param.toString() + ", "; | ||
} else { | ||
paramString += JSON.stringify(param) + ", "; | ||
} | ||
} | ||
paramString = paramString.substring(0, paramString.length -2) + ")"; | ||
return paramString; | ||
}; | ||
@@ -165,0 +210,0 @@ |
{ | ||
"name": "nodemock", | ||
"version": "0.2.3beta", | ||
"version": "0.2.4beta", | ||
"directories": { | ||
@@ -5,0 +5,0 @@ "lib": "./lib" |
@@ -248,1 +248,48 @@ /** | ||
}; | ||
exports.testAssertFailsSameMethod = function(test) { | ||
var mock = nm.mock("foo").takes(10, 20).returns(30); | ||
mock.mock("foo").takes(10, 30).returns(40); | ||
mock.foo(10,20); | ||
test.ok(!mock.assert()); | ||
test.done(); | ||
}; | ||
exports.testAssertFailsManyMethod = function(test) { | ||
var mock = nm.mock("foo").takes(10, 20).returns(30); | ||
mock.mock("bar").takes(10, 30).returns(40); | ||
mock.foo(10,20); | ||
test.ok(!mock.assert()); | ||
test.done(); | ||
}; | ||
exports.testAssertOK = function(test) { | ||
var mock = nm.mock("foo").takes(10, 20).returns(30); | ||
mock.mock("foo").takes(10, 30).returns(40); | ||
mock.mock("bar").returns(30); | ||
mock.foo(10,20); | ||
mock.foo(10,30); | ||
mock.bar(); | ||
test.ok(mock.assert()); | ||
test.done(); | ||
}; | ||
exports.testTimes = function(test) { | ||
var mock = nm.mock("foo").takes(10, 20).times(2); | ||
mock.foo(10, 20); | ||
mock.foo(10, 20); | ||
test.ok(mock.assert()); | ||
mock = nm.mock("bar").takes(10).times(2); | ||
mock.bar(10); | ||
test.ok(!mock.assert()); | ||
test.done(); | ||
}; |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
17760
384