Differences between Mock4JS and jMock 1
Mock4JS is closely based on jMock 1 syntax but there are some differences where I have taken advantage of the dynamic nature of Javascript
Here are a list of differences.
No need for .method() and .with()
In jMock:
mockSubscriber.expects(once()).method("receive").with(eq(message));
In Mock4JS:
mockSubscriber.expects(once()).receive(eq(message));
The eq() constraint is optional
In jMock:
mockSubscriber.expects(once()).method("receive").with(eq(message));
In Mock4JS:
mockSubscriber.expects(once()).receive(
eq(message));
is the same as:
mockSubscriber.expects(once()).receive(
message);
Similarly, in not(), the eq() is optional:
mockSubscriber.expects(once()).receive(
not(eq(message)));
is the same as:
mockSubscriber.expects(once()).receive(
not(message));
No need for onConsecutiveCalls()
In jMock:
mock.stubs.method("getValue").will(onConsecutiveCalls(returnValue(1), throwException(new Exception()));
In Mock4JS:
mock.stubs().getValue().will(returnValue(1), throwException(new Error()));