This method can help you verify that only ONE mocked method call has been made on the entire mock or a specific mocked method. Useful alias!
Boolean $once([methodname])
  • methodName - The optional method name to assert the number of method calls
// let's say we have a service that verifies user credentials
// and if not valid, then tries to check if the user can be inflated from a cookie
// and then verified again
function verifyUser(){
if( isValidUser() ){"user is valid, doing valid operations");
// check if user cookie exists
if( isUserCookieValid() ){
// inflate credentials
// Validate them again
if( NOT isValidUser() ){
log.error("user from cookie invalid, aborting");
// Now the test
it( "can verify a user", function(){
security = getMockBox().createMock("").$("isValidUser",false);
expect( security.$once("isValidUser") ).toBeTrue();
Last modified 6mo ago