Asserter object()

object() behavior

Does not contains assertions from the assertions containers.

test
        .value(test.object({}).hasHeader)
          .isUndefined()
        .value(test.object({}).isError)
          .isUndefined()
        .value(test.object({}).hasMessage)
          .isUndefined()
        .value(test.object({}).isInfinite)
          .isUndefined()
      ;

Assert that the tested value is an object.

var Foo = function Foo(){};
      test
        .object({})
        .object([])
        .object(new Date())
        .object(new RegExp())
        .object(new Foo())
        .case('Test failure', function(){
          test
            .exception(function(){
              test.object('Foo');
            })
            .exception(function(){
              test.object(Foo);
            })
            .exception(function(){
              test.object(1);
            })
            .exception(function(){
              test.object(undefined);
            })
            .exception(function(){
              test.object(true);
            })
            .exception(function(){
              test.object(false);
            })
            .exception(function(){
              test.object(null);
            })
            .exception(function(){
              test.object(function(){});
            })
          ;
        })
      ;

Assertions of object()

is(expected).

test
        .object({fluent: 'is awesome', deep: [0, 1]})
          .is({fluent: 'is awesome', deep: [0, 1]})
        .exception(function(){
          test.object({fluent: 'is awesome', deep: [0, 1]})
            .is({fluent: 'is awesome', deep: [0, 2]});
        })
      ;

isNot(expected).

test
        .object({fluent: 'is awesome', deep: [0, 1]})
          .isNot({fluent: 'is awesome', deep: [0, '1']})
        .exception(function(){
          test.object({fluent: 'is awesome', deep: [0, 1]})
            .isNot({fluent: 'is awesome', deep: [0, 1]});
        })
      ;

isIdenticalTo(expected).

var
  obj = {},
  obj2 = obj
;
test
  .object(obj)
    .isIdenticalTo(obj2)
  .exception(function(){
    test.object(obj).isIdenticalTo({});
  })
;

isNotIdenticalTo(expected).

var
        obj = {},
        obj2 = obj
      ;
      test
        .object(obj)
          .isNotIdenticalTo({})
        .exception(function(){
          test.object(obj).isNotIdenticalTo(obj2);
        })
      ;

isEqualTo(expected).

var
  obj = {},
  obj2 = obj
;
test
  .object(obj)
    .isEqualTo(obj2)
  .exception(function(){
    test.object(obj).isEqualTo({});
  })
;

isNotEqualTo(expected).

var
  obj = {foo: 'bar'},
  obj2 = obj
;
test
  .object(obj)
    .isNotEqualTo({foo: 'bar', baz: 'bar'})
  .exception(function(){
    test.object(obj).isNotEqualTo(obj2);
  })
;

match(expected).

test
        .object({hello: 'world'})
          .match(function(obj){
            return obj.hello == 'world';
          })
        .exception(function(){
          test.object({hello: 'world'})
            .match(function(obj){
              return obj.hello == 'foo';
            });
        })
      ;

notMatch(expected).

test
        .object({hello: 'world'})
          .notMatch(function(obj){
            return obj.hello == 'E.T';
          })
        .exception(function(){
          test.object({hello: 'world'})
            .notMatch(function(obj){
              return obj.hello == 'world';
            })
        })
      ;

isValid(expected).

test
        .object({hello: 'world'})
          .isValid(function(obj){
            return obj.hello == 'world';
          })
        .exception(function(){
          test.object({hello: 'world'})
            .isValid(function(obj){
              return obj.hello == 'foo';
            });
        })
      ;

isNotValid(expected).

test
        .object({hello: 'world'})
          .isNotValid(function(obj){
            return obj.hello == 'E.T';
          })
        .exception(function(){
          test.object({hello: 'world'})
            .isNotValid(function(obj){
              return obj.hello == 'world';
            })
        })
      ;

matchEach(expected).

test
        .object({foo: 'bar', hey: 'you', joker:1})
          .matchEach(function(it, key) {
            if(key == 'joker'){
              return (typeof it == 'number');
            }
            return (typeof it == 'string');
          })
        .exception(function(){
          // error if one or several does not match
          test.object({foo: 'bar', hey: 'you', joker:1})
            .matchEach(function(it, key) {
              return (typeof it == 'string');
            })
        })
      ;

notMatchEach(expected).

test
        .object({foo: 'bar', hey: 'you', joker:1})
          .notMatchEach(function(it, key) {
            if(key == 'other'){
              return true;
            }
          })
        .exception(function(){
          // error if one or several does not match
          test.object({foo: 'bar', hey: 'you', joker:1})
            .notMatchEach(function(it, key) {
              if(key == 'foo'){
                return true;
              }
            })
        })
        .exception(function(){
          // error if one or several does not match
          test.object({foo: 'bar', hey: 'you', joker:1})
            .notMatchEach(function(it, key) {
              return (typeof it == 'string');
            })
        })
      ;

isArray().

test
  .object([])
    .isArray()
  .exception(function(){
    test.object({}).isArray();
  })
  .exception(function(){
    test.object(new Date()).isArray();
  })
;

isRegExp().

test
  .object(/[0-9]+/)
    .isRegExp()
  .exception(function(){
    test.object({}).isRegExp();
  })
  .exception(function(){
    test.object(new Date()).isRegExp();
  })
;

isNotRegExp().

test
  .object(new Date())
    .isNotRegExp()
  .exception(function(){
     test.object(/[0-9]+/).isNotRegExp();
  })
;

isDate().

test
  .object(new Date())
    .isDate()
  .exception(function(){
    test.object({}).isDate();
  })
  .exception(function(){
     test.object(/[0-9]+/).isDate();
  })
;

isNotDate().

test
  .object(/[0-9]+/)
    .isNotDate()
  .exception(function(){
    test.object(new Date()).isNotDate();
  })
;

isArguments().

var fn = function(){
        var args = arguments;
        test.object(arguments).isArguments();
        test.object(args).isArguments();
      };
      fn(1, 2, 3);
      test.exception(function(){
        test.object({0: 'a'}).isArguments();
      });

isNotArguments().

var fn = function(){
        test
          .object(arguments)
            .isArguments()
          .object([1, 2, 3])
            .isNotArguments()
          .object({0:1, 1:2, 2:3})
            .isNotArguments()
        ;
      };
      fn(1, 2, 3);
      test.exception(function(){
        test.object(arguments).isNotArguments();
      });

isEmpty().

test
  .object({})
    .isEmpty()
  .exception(function(){
    test.object({0: 'a'}).isEmpty();
  })
;

isNotEmpty().

test
  .object({hello: 'Nico'})
    .isNotEmpty()
  .exception(function(){
    test.object({}).isNotEmpty();
  })
;

hasLength(expected).

test
        .object({foo: 'bar', other: 'baz'})
          .hasLength(2)
        .exception(function(){
          test.object({foo: 'bar', other: 'baz'})
            .hasLength(3);
        })
      ;

hasNotLength(expected).

test
        .object({foo: 'bar', other: 'baz'})
          .hasNotLength(4)
        .exception(function(){
          test.object({foo: 'bar', other: 'baz'})
            .hasNotLength(2);
        })
      ;

isEnumerable(property).

test
        .object({prop: 'foobar'})
          .isEnumerable('prop')
        .exception(function(){
          test.object({prop: 'foobar'})
            .isEnumerable('length');
        })
      ;

isNotEnumerable(property).

test
        .object(Object.create({}, {prop: {enumerable: 0}}))
          .isNotEnumerable('prop')
        .exception(function(){
          test.object({prop: 'foobar'})
            .isNotEnumerable('prop');
        })
      ;

isFrozen().

test
  .object(Object.freeze({}))
    .isFrozen()
  .exception(function(){
    test.object({})
      .isFrozen();
  })
;

isNotFrozen().

test
  .object({})
    .isNotFrozen()
  .exception(function(){
    test.object(Object.freeze({}))
      .isNotFrozen();
  })
;

isInstanceOf(expected).

test
  .object(new Date())
    .isInstanceOf(Date)
  .exception(function(){
    test.object(new Date())
      .isInstanceOf(Error);
  })
;

isNotInstanceOf(expected).

test
  .object(new Date())
    .isNotInstanceOf(RegExp)
  .exception(function(){
    test.object(new Date())
      .isNotInstanceOf(Object);
  })
  .exception(function(){
    test.object(new Date())
      .isNotInstanceOf(Date);
  })
;

hasProperty(property [, value]).

test
  .object({foo: 'bar'})
    .hasProperty('foo')
  .object({foo: 'bar'})
    .hasProperty('foo', 'bar')
  .exception(function(){
    test.object({foo: 'bar'})
      .hasProperty('bar');
  })
  .exception(function(){
    test.object({foo: 'bar'})
      .hasProperty('foo', 'ba');
  })
;

hasNotProperty(property [, value]).

test
  .object({foo: 'bar'})
    .hasNotProperty('bar')
  .object({foo: 'bar'})
    .hasNotProperty('foo', 'baz')
  .exception(function(){
    test.object({foo: 'bar'})
      .hasNotProperty('foo');
  })
  .exception(function(){
    test.object({foo: 'bar'})
      .hasNotProperty('foo', 'bar');
  })
;

hasOwnProperty(property [, value]).

test
  .object({foo: 'bar'})
    .hasOwnProperty('foo')
  .object({foo: 'bar'})
    .hasOwnProperty('foo', 'bar')
  .exception(function(){
    test.object({foo: 'bar'})
      .hasOwnProperty('bar');
  })
  .exception(function(){
    test.object({foo: 'bar'})
      .hasOwnProperty('foo', 'ba');
  })
;

hasNotOwnProperty(property [, value]).

test
  .object({foo: 'bar'})
    .hasNotOwnProperty('bar')
  .object({foo: 'bar'})
    .hasNotOwnProperty('foo', 'baz')
  .exception(function(){
    test.object({foo: 'bar'})
      .hasNotOwnProperty('foo');
  })
  .exception(function(){
    test.object({foo: 'bar'})
      .hasNotOwnProperty('foo', 'bar');
  })
;

hasProperties(properties).

test
  .object({foo: 'bar', bar: 'huhu', other: 'vroom'})
    .hasProperties(['other', 'bar', 'foo'])
  .exception(function(){
    test.object({foo: 'bar', bar: 'huhu', other: 'vroom'})
      .hasProperties(['other', 'bar']);
  })
;

hasNotProperties(properties).

test
  .object({foo: 'bar', bar: 'huhu', other: 'vroom'})
    .hasNotProperties(['other', 'foo'])
  .exception(function(){
    test.object({foo: 'bar', bar: 'huhu', other: 'vroom'})
      .hasNotProperties(['bar', 'other', 'foo']);
  })
;

hasOwnProperties(properties).

test
  .object({foo: 'bar', bar: 'huhu', other: 'vroom'})
    .hasOwnProperties(['other', 'bar', 'foo'])
  .exception(function(){
    test.object({foo: 'bar', bar: 'huhu', other: 'vroom'})
      .hasOwnProperties(['other', 'bar']);
  })
;

hasKey(key [, value]).

test
  .object({foo: 'bar'})
    .hasKey('foo')
  .object({foo: 'bar'})
    .hasKey('foo', 'bar')
  .exception(function(){
    test.object({foo: 'bar'})
      .hasKey('bar');
  })
  .exception(function(){
    test.object({foo: 'bar'})
      .hasKey('foo', 'ba');
  })
;

notHasKey(key [, value]).

test
  .object({foo: 'bar'})
    .notHasKey('bar')
  .object({foo: 'bar'})
    .notHasKey('foo', 'baz')
  .exception(function(){
    test.object({foo: 'bar'})
      .notHasKey('foo');
  })
  .exception(function(){
    test.object({foo: 'bar'})
      .notHasKey('foo', 'bar');
  })
;

hasKeys(keys).

test
  .object({foo: 'bar', bar: 'huhu', other: 'vroom'})
    .hasKeys(['other', 'bar', 'foo'])
  .exception(function(){
    test.object({foo: 'bar', bar: 'huhu', other: 'vroom'})
      .hasKeys(['other', 'bar']);
  })
;

notHasKeys(keys).

test
  .object({foo: 'bar', bar: 'huhu', other: 'vroom'})
    .notHasKeys(['other', 'foo'])
  .exception(function(){
    test.object({foo: 'bar', bar: 'huhu', other: 'vroom'})
      .notHasKeys(['bar', 'other', 'foo']);
  })
;

hasValue(expected).

test
        .object({life: 42, love: 69})
          .hasValue(42)
        .exception(function(){
          test.object({life: 42, love: 69})
            .hasValue('42');
        })
      ;

notHasValue(expected).

test
        .object({life: 42, love: 69})
          .notHasValue(4)
        .exception(function(){
          test.object({life: 42, love: 69})
            .notHasValue(42);
        })
      ;

hasValues(expected).

test
        .object({life: 42, love: 69})
          .hasValues([42, 69])
        .exception(function(){
          test.object([1, 42, 3])
            .hasValues([42, 3.01]);
        })
      ;

notHasValues(expected).

test
        .object({life: 42, love: 69})
          .notHasValues([43, 68])
        .exception(function(){
          test.object([1, 42, 3])
            .notHasValues([1, 42, 3]);
        })
      ;

contains(expected [, ...]).

test
        .object({ a: { b: 10 }, b: { c: 10, d: 11, a: { b: 10, c: 11} }})
        .contains({ a: { b: 10 }, b: { c: 10, a: { c: 11 }}})
        .object({a: 'a', b: {c: 'c'}})
          .contains({b: {c: 'c'}})
          .contains({b: {c: 'c'}}, {a: 'a'})
        .exception(function(){
          test.object({foo: {a: 'a'}, bar: {b: 'b', c: 'c'}})
            .contains({foo: {a: 'a'}}, {bar: {b: 'c'}});
        })
      ;

notContains(expected [, ...]).

test
        .object({a: 'a'}, {b: 'b', c: 'c'})
          .notContains({c: 'b'})
        .exception(function(){
          test.object({foo: {a: 'a'}, bar: {b: 'b', c: 'c'}})
            .notContains({foo: {a: 'a'}, bar: {c: 'c'}});
        })
      ;

hasName(expected).

test
        .object(new Date(2010, 5, 28))
          .hasName('Date')
        .exception(function(){
          test.object(new Date(2010, 5, 28))
            .hasName('date');
        })
      ;