Comparing version 0.3.2 to 0.3.3
@@ -186,2 +186,3 @@ /** | ||
var messages = [], | ||
mock = this, | ||
methodName, | ||
@@ -195,3 +196,3 @@ method, | ||
methodName = self.context ? self.context + "#" + method : method; | ||
messages.push("Method " + methodName + getParamString(entry.args) + " was not called"); | ||
messages.push("Method " + mock._name + methodName + getParamString(entry.args) + " was not called"); | ||
} | ||
@@ -364,5 +365,14 @@ }); | ||
if(typeof(exports) != "undefined") { | ||
var currentName = ''; | ||
exports.named = function(mockName) { | ||
currentName = mockName; | ||
return exports; | ||
}; | ||
exports.mock = function(methodName) { | ||
return new NodeMock(methodName); | ||
var mock = new NodeMock(methodName); | ||
mock._name = currentName? currentName + '.' : ''; | ||
currentName = ''; | ||
return mock; | ||
}; | ||
@@ -369,0 +379,0 @@ |
{ | ||
"name": "nodemock", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"directories": { | ||
@@ -5,0 +5,0 @@ "test": "test" |
@@ -48,2 +48,13 @@ A simple Yet Powerful Mocking Framework for NodeJs | ||
### Name a mock for clarity | ||
var mocks = [ | ||
nodemock.named('mock1').mock('foo').takes(1), | ||
nodemock.named('mock2').mock('foo').takes(1) | ||
], | ||
i; | ||
for(i = 0; i < mocks.length; i += 1) { | ||
mocks[i].assert(); // Prints that «mockName».foo(1) was not called. | ||
} | ||
### Creating a mock function with taking arguments and return value | ||
@@ -50,0 +61,0 @@ var mocked = nodemock.mock("foo").takes(10, [10, 20, 30]).returns(98); |
@@ -30,2 +30,15 @@ /* | ||
exports.mocksHaveNames = function(test) { | ||
var mockName = 'myFabulousMock', | ||
mock = nm.named(mockName).mock('foo').takes(1); | ||
try { | ||
mock.assertThrows(); | ||
} catch(e) { | ||
test.ok(e.message.indexOf(mockName) > -1); | ||
} | ||
test.expect(1); | ||
test.done(); | ||
}; | ||
exports.testArgumentSimple = function(test) { | ||
@@ -251,3 +264,3 @@ | ||
var mock = nm.mock("foo").takes(10, 20).returns(30); | ||
var mock = nm.named('mocky').mock("foo").takes(10, 20).returns(30); | ||
mock.mock("foo").takes(10, 30).returns(40); | ||
@@ -262,3 +275,3 @@ | ||
var mock = nm.mock("foo").takes(10, 20).returns(30); | ||
var mock = nm.named('mockier').mock("foo").takes(10, 20).returns(30); | ||
mock.mock("bar").takes(10, 30).returns(40); | ||
@@ -265,0 +278,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33229
726
285