Asserter exception()

exception() behavior

Does not contains assertions from the assertions containers.

test
        .value(test.exception(function(){ throw new Error('hu'); }).hasHeader)
          .isUndefined()
        .value(test.exception(function(){ throw new Error('hu'); }).isBetween)
          .isUndefined()

Takes a function that will throws an exception.

var
        indicator,
        trigger = function(){
          indicator = true;
          throw new Error("I'm a ninja !");
        }
      ;
      // Apply the trigger and assert that an exception is thrown
      test
        .exception(trigger)
        // just for the example and for the test
        .bool(indicator).isTrue()
        .given(indicator = false)
          .exception(function(){
            indicator = true;
            throw new Error('Whoops!');
          })
          // just for the example and for the test
          .bool(indicator).isTrue()
      ;

Error if the trigger don't throws an exception.

var indicator;
      test
        .given(indicator = false)
          .value(function(){
            // no error thrown by the trigger,
            // then throw 'Error: Missing expected exception'
            test.exception(function(){
              indicator = true;
            });
          })
          .throws()
          // just for the example and for the test
          .bool(indicator).isTrue()
      ;

Assert that thrown with the Error class and a given message.

var
        // create an indicator for monitoring the example and the test
        indicator = test.createCollection(),
        fn = function(){
          indicator.set('error constructor called', true);
          throw new Error("I'm a ninja !");
        },
        resetIndicator = function(){
          // empty
          indicator.setAll({});
        },
        exception
      ;
      test
        .exception(fn)
          .isError()
          .hasMessage("I'm a ninja !")
        // just for the example and for the test
        .bool(indicator.get('error constructor called')).isTrue()
        .when(exception = test.exception(fn))
          .exception(function(){
            // fails because is not the error message
            exception.isError().hasMessage("I'm a not ninja !");
          })
        .given(resetIndicator())
          // Assert that thrown with the Error class
          // and with the message (regExp)
          .exception(fn)
            .isError()
            .hasMessage(/ninja/)
          // just for the example and for the test
          .bool(indicator.get('error constructor called')).isTrue()
          .when(exception = test.exception(fn))
            .exception(function(){
              // fails because 'ninjaa' is not in error message
              exception.isError().hasMessage(/ninjaa/);
            })
        .given(resetIndicator())
          .exception(function(){
            indicator.set('Whoops error, is called', true);
            throw new Error('Whoops!');
          })
          .hasMessage('Whoops!')
          .isInstanceOf(Error)
          // just for the example and for the test
          .bool(indicator.get('Whoops error, is called')).isTrue()
      ;

Assertions of exception()

is(expected).

var error = new Error('Whoops !');
      var trigger = function(){
        throw error;
      };
      test
        .exception(trigger)
          .is(error)
          .is(new Error('Whoops !'))
        .case('Test failure', function(){
          test
            .value(function(){
              test.exception(trigger).is({message: 'Whoops !'});
            })
            .throws()
            .value(function(){
              test.exception(trigger).is(new String('Whoops !'));
            })
            .throws()
          ;
        }) // end: Test failure
      ;

isNot(expected).

var error = new Error('Whoops !');
var trigger = function(){
  throw error;
};
test
  .exception(trigger)
    .isNot({message: 'Whoops !'})
  // Test failure
  .value(function(){
    test.exception(trigger).isNot(error);
  })
  .throws()
;

isIdenticalTo(expected).

var error = new Error('Whoops !');
      var trigger = function(){
        throw error;
      };
      test
        .exception(trigger)
          .isIdenticalTo(error)
        // Test failure
        .value(function(){
          test.exception(trigger).isIdenticalTo(new Error('Whoops !'));
        })
        .throws()
      ;

isNotIdenticalTo(expected).

var error = new Error('Whoops !');
      var trigger = function(){
        throw error;
      };
      test
        .exception(trigger)
          .isNotIdenticalTo(new Error('Whoops !'))
        // Test failure
        .value(function(){
          test.exception(trigger).isNotIdenticalTo(error);
        })
        .throws()
      ;

isEqualTo(expected).

var error = new Error('Whoops !');
      var trigger = function(){
        throw error;
      };
      test
        .exception(trigger)
          .isEqualTo(error)
        // Test failure
        .value(function(){
          test.exception(trigger).isEqualTo(new Error('Whoops !'));
        })
        .throws()
      ;

isNotEqualTo(expected).

var error = new Error('Whoops !');
      var trigger = function(){
        throw error;
      };
      test
        .exception(trigger)
          .isNotEqualTo(new Error('Whoops !'))
        // Test failure
        .value(function(){
          test.exception(trigger).isNotEqualTo(error);
        })
        .throws()
      ;

match(expected).

var
        // create an indicator for monitoring the example and the test
        indicator = test.createCollection(),
        trigger = function(){
          indicator.set('error trigger called', true);
          throw new Error('Whoops!');
        }
      ;
      test
        .exception(trigger)
          .match('Whoops!')
          .match(/Whoops/)
          .match(function(exception){
            indicator.set('custom error validation called', true);
            return (exception instanceof Error) && /whoops/i.test(exception);
          })
        // just for the example and for the test
        .bool(indicator.get('error trigger called')).isTrue()
        .bool(indicator.get('custom error validation called')).isTrue()
        .case('Test failure', function(){
          test
            .value(function(){
              test.exception(trigger).match('Hey');
            })
            .throws()
            .value(function(){
              test.exception(trigger).match(/Hey/);
            })
            .throws()
            .value(function(){
              test.exception(trigger).match(function(error){
                return error instanceof RegExp;
              });
            })
            .throws()
          ;
        }) // end: Test failure
      ;

notMatch(expected).

var
        // create an indicator for monitoring the example and the test
        indicator = test.createCollection(),
        trigger = function(){
          indicator.set('error trigger called', true);
          throw new Error('Whoops!');
        }
      ;
      test
        .exception(trigger)
          .notMatch('Yeah an error')
          .notMatch(/Yeah/)
          .notMatch(function(exception){
            indicator.set('custom error validation called', true);
            return /yeah/.test(exception);
          })
        // just for the example and for the test
        .bool(indicator.get('error trigger called')).isTrue()
        .bool(indicator.get('custom error validation called')).isTrue()
        .case('Test failure', function(){
          test
            .value(function(){
              test.exception(trigger).notMatch('Whoops!');
            })
            .throws()
            .value(function(){
              test.exception(trigger).notMatch(/Whoops/);
            })
            .throws()
          ;
        }) // end: Test failure
      ;

isValid(expected).

var
        // create an indicator for monitoring the example and the test
        indicator = test.createCollection(),
        trigger = function(){
          indicator.set('error trigger called', true);
          throw new Error('Whoops!');
        }
      ;
      test
        .exception(trigger)
          .isValid('Whoops!')
          .isValid(/Whoops/)
          .isValid(function(exception){
            indicator.set('custom error validation called', true);
            return (exception instanceof Error) && /whoops/i.test(exception);
          })
        // just for the example and for the test
        .bool(indicator.get('error trigger called')).isTrue()
        .bool(indicator.get('custom error validation called')).isTrue()
        .case('Test failure', function(){
          test
            .value(function(){
              test.exception(trigger).isValid('Hey');
            })
            .throws()
            .value(function(){
              test.exception(trigger).isValid(/Hey/);
            })
            .throws()
            .value(function(){
              test.exception(trigger).isValid(function(error){
                return error instanceof RegExp;
              });
            })
            .throws()
          ;
        }) // end: Test failure
      ;

isNotValid(expected).

var
        // create an indicator for monitoring the example and the test
        indicator = test.createCollection(),
        trigger = function(){
          indicator.set('error trigger called', true);
          throw new Error('Whoops!');
        }
      ;
      test
        .exception(trigger)
          .isNotValid('Yeah an error')
          .isNotValid(/Yeah/)
          .isNotValid(function(exception){
            indicator.set('custom error validation called', true);
            return /yeah/.test(exception);
          })
        // just for the example and for the test
        .bool(indicator.get('error trigger called')).isTrue()
        .bool(indicator.get('custom error validation called')).isTrue()
        .case('Test failure', function(){
          test
            .value(function(){
              test.exception(trigger).isNotValid('Whoops!');
            })
            .throws()
            .value(function(){
              test.exception(trigger).isNotValid(/Whoops/);
            })
            .throws()
          ;
        }) // end: Test failure
      ;

isType(expected).

var trigger = function(){
        throw new Error('Whoops !');
      };
      test
        .exception(trigger)
          .isType('object')
        .exception(function(){
          throw 'Whoops !';
        })
        .isType('string')
        // Test failure
        .value(function(){
          test.exception(trigger).isType('function');
        })
        .throws()
      ;

isNotType(expected).

var trigger = function(){
        throw new Error('Whoops !');
      };
      test
        .exception(trigger)
          .isNotType('string')
        .exception(function(){
          throw 'Whoops !';
        })
        .isNotType('object')
        // Test failure
        .value(function(){
          test.exception(trigger).isNotType('object');
        })
        .throws()
      ;

isObject().

test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .isObject()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw 'error';
            })
            .isObject()
          ;
        })
        .throws()
      ;

isArray().

test
        .exception(function(){
          throw ['error'];
        })
        .isArray()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Error('Whoops !');
            })
            .isArray()
          ;
        })
        .throws()
      ;

isString().

test
        .exception(function(){
          throw 'error';
        })
        .isString()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Error('Whoops !');
            })
            .isString()
          ;
        })
        .throws()
      ;

isNumber().

test
        .exception(function(){
          throw 0;
        })
        .isNumber()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw '0';
            })
            .isNumber()
          ;
        })
        .throws()
      ;

isBool().

test
        .exception(function(){
          throw false;
        })
        .isBool()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw 0;
            })
            .isBool()
          ;
        })
        .throws()
      ;

isBoolean().

test
        .exception(function(){
          throw true;
        })
        .isBoolean()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw 1;
            })
            .isBoolean()
          ;
        })
        .throws()
      ;

isNull().

test
        .exception(function(){
          throw null;
        })
        .isNull()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw 0;
            })
            .isNull()
          ;
        })
        .throws()
      ;

isUndefined().

test
        .exception(function(){
          throw undefined;
        })
        .isUndefined()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw 0;
            })
            .isUndefined()
          ;
        })
        .throws()
      ;

isRegExp().

test
        .exception(function(){
          throw new RegExp('whoops');
        })
        .isRegExp()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Error('Whoops !');
            })
            .isRegExp()
          ;
        })
        .throws()
      ;

isNotRegExp().

test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .isNotRegExp()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new RegExp('whoops');
            })
            .isNotRegExp()
          ;
        })
        .throws()
      ;

isDate().

test
        .exception(function(){
          throw new Date();
        })
        .isDate()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Error('Whoops !');
            })
            .isDate()
          ;
        })
        .throws()
      ;

isNotDate().

test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .isNotDate()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Date();
            })
            .isNotDate()
          ;
        })
        .throws()
      ;

isArguments().

var error = function(){
        return arguments;
      };
      test
        .exception(function(){
          throw error(1, 2, 3);
        })
        .isArguments()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Error('Whoops !');
            })
            .isArguments()
          ;
        })
        .throws()
      ;

isNotArguments().

var error = function(){
        return arguments;
      };
      test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .isNotArguments()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw error(1, 2, 3);
            })
            .isNotArguments()
          ;
        })
        .throws()
      ;

isEmpty().

test
        .exception(function(){
          throw '';
        })
        .isEmpty()
        .exception(function(){
          throw [];
        })
        .isEmpty()
        .exception(function(){
          throw {};
        })
        .isEmpty()
        // Indeed an instance of `Error` has no enumerable properties.
        .exception(function(){
          throw new Error('Whoops !');
        })
        .isEmpty()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw 'Whoops !';
            })
            .isEmpty()
          ;
        })
        .throws()
      ;

isNotEmpty().

test
        .exception(function(){
          throw 'Whoops !';
        })
        .isNotEmpty()
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw '';
                })
                .isNotEmpty()
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw [];
                })
                .isNotEmpty()
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {};
                })
                .isNotEmpty()
              ;
            })
            .throws()
            .value(function(){
              // Indeed an instance of `Error` has no enumerable properties.
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .isNotEmpty()
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

isError().

// isError() assertion is an alias of isInstanceOf(Error)
      var
        // create an indicator for monitoring the example and the test
        indicator = test.createCollection(),
        trigger = function(){
          indicator.set('error constructor called', true);
          throw new Error("I'm a ninja !");
        },
        resetIndicator = function(){
          // empty
          indicator.setAll({});
        }
      ;
      test
        // Assert that thrown with the Error class
        .exception(trigger)
          .isInstanceOf(Error)
        // just for the example and for the test
        .bool(indicator.get('error constructor called')).isTrue()
        // or shortcut
        .given(resetIndicator())
          // Assert that thrown with the Error class
          .exception(trigger)
            .isError()
          // just for the example and for the test
          .bool(indicator.get('error constructor called')).isTrue()
      ;

hasLength(expected).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasLength(2)
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw {message: 'error', code: 42};
            })
            .hasLength(1)
          ;
        })
        .throws()
      ;

hasNotLength(expected).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasNotLength(1)
        .hasNotLength(3)
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw {message: 'error', code: 42};
            })
            .hasNotLength(2)
          ;
        })
        .throws()
      ;

isEnumerable(property).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .isEnumerable('message')
        .isEnumerable('code')
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Error('Whoops !');
            })
            .isEnumerable('message')
          ;
        })
        .throws()
      ;

isNotEnumerable(property).

test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .isNotEnumerable('message')
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw {message: 'error', code: 42};
            })
            .isNotEnumerable('message')
          ;
        })
        .throws()
      ;

isFrozen().

var
        error = {message: 'error', code: 42},
        frozenError = {message: 'error', code: 42}
      ;
      Object.freeze(frozenError);
      test
        .exception(function(){
          throw frozenError;
        })
        .isFrozen()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw error;
            })
            .isFrozen()
          ;
        })
        .throws()
      ;

isNotFrozen().

var
        error = {message: 'error', code: 42},
        frozenError = {message: 'error', code: 42}
      ;
      Object.freeze(frozenError);
      test
        .exception(function(){
          throw error;
        })
        .isNotFrozen()
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw frozenError;
            })
            .isNotFrozen()
          ;
        })
        .throws()
      ;

isInstanceOf(expected).

test
        .exception(function(){
          throw new TypeError('Whoops !');
        })
        .isInstanceOf(TypeError)
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new Error('Bad type');
            })
            .isInstanceOf(TypeError)
          ;
        })
        .throws()
      ;

isNotInstanceOf(expected).

test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .isNotInstanceOf(TypeError)
        // Test failure
        .value(function(){
          test
            .exception(function(){
              throw new TypeError('Bad type');
            })
            .isNotInstanceOf(TypeError)
          ;
        })
        .throws()
      ;

hasProperty(property [, value]).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasProperty('message')
        .hasProperty('code', 42)
        .exception(function(){
          throw new Error('Whoops !');
        })
        .hasProperty('message')
        .hasProperty('message', 'Whoops !')
        .hasProperty('constructor')
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasProperty('foo')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasProperty('code', 1)
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasNotProperty(property [, value]).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasNotProperty('foo')
        .hasNotProperty('code', 1)
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasNotProperty('message')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasNotProperty('code', 42)
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .hasNotProperty('constructor')
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasOwnProperty(property [, value]).

test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .hasOwnProperty('message')
        .hasOwnProperty('message', 'Whoops !')
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .hasOwnProperty('foo')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .hasOwnProperty('message', 'Grrrr !')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .hasOwnProperty('constructor')
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasNotOwnProperty(property [, value]).

test
        .exception(function(){
          throw new Error('Whoops !');
        })
        .hasNotOwnProperty('foo')
        .hasNotOwnProperty('message', 'Grrrr !')
        .hasNotOwnProperty('constructor')
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .hasNotOwnProperty('message')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .hasNotOwnProperty('message', 'Whoops !')
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasProperties(properties).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasProperties(['message', 'code'])
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasProperties(['message', 'code', 'foo'])
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasProperties(['message'])
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasNotProperties(properties).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasNotProperties(['foo', 'bar'])
        .hasNotProperties(['foo', 'code', 'bar'])
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasNotProperties(['message', 'code'])
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasOwnProperties(properties).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasOwnProperties(['message', 'code'])
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasOwnProperties(['message', 'code', 'foo'])
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasOwnProperties(['message'])
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasKey(key [, value]).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasKey('message')
        .hasKey('code', 42)
        .exception(function(){
          throw new Error('Whoops !');
        })
        .hasKey('message')
        .hasKey('message', 'Whoops !')
        .hasKey('constructor')
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasKey('foo')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasKey('code', 1)
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

notHasKey(key [, value]).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .notHasKey('foo')
        .notHasKey('code', 1)
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .notHasKey('message')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .notHasKey('code', 42)
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw new Error('Whoops !');
                })
                .notHasKey('constructor')
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasKeys(keys).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasKeys(['message', 'code'])
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasKeys(['message', 'code', 'foo'])
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasKeys(['message'])
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

notHasKeys(keys).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .notHasKeys(['foo', 'bar'])
        .notHasKeys(['foo', 'code', 'bar'])
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .notHasKeys(['message', 'code'])
              ;
            })
            .throws()
          ;
        }) // end: Test failure
      ;

hasValue(expected).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasValue('error')
        .hasValue(42)
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasValue('err')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasValue(2)
              ;
            })
            .throws()
        })
      ;

notHasValue(expected).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .notHasValue('err')
        .notHasValue(2)
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .notHasValue('error')
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .notHasValue(42)
              ;
            })
            .throws()
        })
      ;

hasValues(expected).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .hasValues(['error'])
        .hasValues(['error', 42])
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasValues(['foo'])
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .hasValues(['error', 42, 'foo'])
              ;
            })
            .throws()
        })
      ;

notHasValues(expected).

test
        .exception(function(){
          throw {message: 'error', code: 42};
        })
        .notHasValues(['code'])
        .notHasValues(['message', 'code', 'foo'])
        .case('Test failure', function(){
          test
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .notHasValues(['error'])
              ;
            })
            .throws()
            .value(function(){
              test
                .exception(function(){
                  throw {message: 'error', code: 42};
                })
                .notHasValues(['foo', 'error'])
              ;
            })
            .throws()
        })
      ;

contains(expected [, ...]).

test
        .exception(function(){
          throw new Error('Whoops');
        })
        .contains({message: 'Whoops'})
        // Test failure
        .value(function(){
            test
              .exception(function(){
                throw new Error('Whoops');
              })
              .contains({message: 'foo'})
            ;
          })
          .throws()
      ;

notContains(expected [, ...]).

test
        .exception(function(){
          throw new Error('Whoops');
        })
        .notContains({message: 'foo'})
        // Test failure
        .value(function(){
            test
              .exception(function(){
                throw new Error('Whoops');
              })
              .notContains({message: 'Whoops'})
            ;
          })
          .throws()
      ;

startsWith(str).

test
        .exception(function(){
          throw 'An error occured';
        })
        .startsWith('An error')
        // Test failure
        .value(function(){
            test
              .exception(function(){
                throw 'An error occured';
              })
              .startsWith('error')
            ;
          })
          .throws()
      ;

notStartsWith(str).

test
        .exception(function(){
          throw 'An error occured';
        })
        .notStartsWith('error')
        // Test failure
        .value(function(){
            test
              .exception(function(){
                throw 'An error occured';
              })
              .notStartsWith('An error')
            ;
          })
          .throws()
      ;

endsWith(str).

test
        .exception(function(){
          throw 'An error occured';
        })
        .endsWith('occured')
        // Test failure
        .value(function(){
            test
              .exception(function(){
                throw 'An error occured';
              })
              .endsWith('error')
            ;
          })
          .throws()
      ;

notEndsWith(str).

test
        .exception(function(){
          throw 'An error occured';
        })
        .notEndsWith('error')
        // Test failure
        .value(function(){
            test
              .exception(function(){
                throw 'An error occured';
              })
              .notEndsWith('occured')
            ;
          })
          .throws()
      ;

hasMessage(expected).

var
        // create an indicator for monitoring the example and the test
        indicator = test.createCollection(),
        trigger = function(){
          indicator.set('error constructor called', true);
          throw new Error("I'm a ninja !");
        },
        resetIndicator = function(){
          // empty
          indicator.setAll({});
        },
        exception
      ;
      test
        .exception(trigger)
          .hasMessage("I'm a ninja !")
        // just for the example and for the test
        .bool(indicator.get('error constructor called')).isTrue()
        // reset indicator
        // 'then' does nothing, is just pass-through method for a fluent chain.
        .then(resetIndicator())
          .exception(trigger)
            .hasMessage(/ninja/)
          // just for the example and for the test
          .bool(indicator.get('error constructor called')).isTrue()
        // reset indicator
        .then(resetIndicator())
        // out of trigger block,
        // because test.exception(trigger) throws the trigger in the block
        // also you can use test.value().throws() (see after)
        .case(exception = test.exception(trigger))
          .exception(function(){
            indicator.set('ninjaa is not in error message', true);
            // fails because ninjaa is not in error message
            exception.hasMessage(/ninjaa/);
          })
          // just for the example and for the test
          .bool(indicator.get('error constructor called')).isTrue()
          .bool(indicator.get('ninjaa is not in error message')).isTrue()
        // the above example is equal to
        .then(resetIndicator())
          .value(function(){
            indicator.set('ninjaa is not in error message', true);
            // fails because ninjaa is not in error message
            test.exception(trigger).hasMessage(/ninjaa/);
          })
          .throws()
          // just for the example and for the test
          .bool(indicator.get('error constructor called')).isTrue()
          .bool(indicator.get('ninjaa is not in error message')).isTrue()
      ;