Mock4JS: Constraints

Method Constraints

These are the constraints you can use with expects(). For example:
mockObject.expects(once()).someMethod()

Argument Constraints

These are the constraints you can use with method arguments. For example:
mockObject.expects(once()).someMethod(eq("arg1"), ANYTHING, stringContains("hello"))

Method Actions

These are the behaviours that a mock can exhibit when an expected method is invoked. For example:
mockObject.expects(once()).someMethod().will(returnValue("someResult"))
Note that you can specify a list of actions. This allows you to change the behaviour of the mocked method on consequtive calls. For example:
mockObject.expects(exactly(3)).someMethod().will(returnValue("result1"), returnValue("result2"), throwException(new Error("problemo!")))

SourceForge.net Logo