Asserter string()

string() behavior

Does not contains assertions from the assertions containers.

test
        .value(test.string('').hasHeader)
          .isUndefined()
        .value(test.string('').hasProperty)
          .isUndefined()
        .value(test.string('').hasMessage)
          .isUndefined()
        .value(test.string('').isInfinite)
          .isUndefined()
      ;

Assert that the tested value is a string.

test
        .string('')
        .string('Hello')
        .case('Test failure', function(){
          test
            .exception(function(){
              test.string();
            })
            .exception(function(){
              test.string({});
            })
            .exception(function(){
              test.string([]);
            })
            .exception(function(){
              test.string(1);
            })
            .exception(function(){
              test.string(/foobar/);
            })
            .exception(function(){
              test.string(true);
            })
            .exception(function(){
              test.string(false);
            })
            .exception(function(){
              test.string(null);
            })
            .exception(function(){
              test.string(undefined);
            })
          ;
        })
      ;

Assertions of string()

is(expected).

var str = 'Hello world !';
      test
        .string(str)
          .is('Hello world !')
        .exception(function(){
          test.string(str).is('foo');
        })
      ;

isNot(expected).

var str = 'Hello world !';
      test
        .string(str)
          .isNot('hello world !')
        .exception(function(){
          test.string(str).isNot('Hello world !');
        })
      ;

isIdenticalTo(expected).

var str = 'Hello world !';
      test
        .string(str)
          .isIdenticalTo('Hello world !')
        .exception(function(){
          test.string(str).isIdenticalTo('Hello World !');
        })
      ;

isNotIdenticalTo(expected).

var str = 'Hello world !';
      test
        .string(str)
          .isNotIdenticalTo('hello world !')
        .exception(function(){
          test.string(str).isNotIdenticalTo('Hello world !');
        })
      ;

isEqualTo(expected).

var str = 'Hello world !';
      test
        .string(str)
          .isEqualTo('Hello world !')
        .exception(function(){
          test.string(str).isEqualTo('Hello World !');
        })
      ;

isNotEqualTo(expected).

var str = 'Hello world !';
      test
        .string(str)
          .isNotEqualTo('hello world !')
        .exception(function(){
          test.string(str).isNotEqualTo('Hello world !');
        })
      ;

match(expected).

// Assert a string value with a expected string
      test.string('Hello').match('Hello');
      // Assert a string value with a RegExp
      test.string('Hello world !').match(/world/i);
      // Assert a string with a function
      test.string('hello').match(function(it){
        return it === 'hello';
      });
      test.exception(function(){
        test.string('hello').match(/foo/);
      });

notMatch(expected).

test
        .string('foobar')
          .notMatch('some value')
          .notMatch(/[foo]+bazzz$/)
        .string('foo')
          .notMatch(function(it){
            return it === 'bar';
          })
        .exception(function(){
          test.string('Hello Nico!').notMatch(/nico/i);
        })
      ;

isValid(expected).

// Assert a string value with a expected string
      test.string('Hello').isValid('Hello');
      // Assert a string value with a RegExp
      test.string('Hello world !').isValid(/world/i);
      // Assert a string with a function
      test.string('hello').isValid(function(it){
        return it === 'hello';
      });
      test.exception(function(){
        test.string('hello').isValid(/foo/);
      });

isNotValid(expected).

test
        .string('foobar')
          .isNotValid('some value')
          .isNotValid(/[foo]+bazzz$/)
        .string('foo')
          .isNotValid(function(it){
            return it === 'bar';
          })
        .exception(function(){
          test.string('Hello Nico!').notMatch(/nico/i);
        })
      ;

matchEach(expected).

var str = 'Hello Nico!';
      test
        .string(str)
          .matchEach([/hello/i, 'Nico', function(it){
            return it === 'Hello Nico!';
          }])
        .case('Test failure', function(){
          test
            .exception(function(){
              test.string(str).matchEach([/hello/i, 'nico', function(it){
                return it === 'Hello Nico!';
              }]);
            })
            .exception(function(){
              test.string(str).matchEach([/hello/i, 'Nico', function(it){
                return it === 'Hello nico!';
              }]);
            })
          ;
        })
      ;

notMatchEach(expected).

var str = 'Hello Nico!';
      test
        .string(str)
          .notMatchEach([/foo/i, 'bad word', function(it){
            return it === 'Bye';
          }])
        .case('Test failure', function(){
          test
            .exception(function(){
              test.string(str).notMatchEach([/hello/, 'Nico', function(it){
                return it === 'Hello !';
              }]);
            })
            .exception(function(){
              test.string(str).notMatchEach([/hello/, 'nico', function(it){
                return it === 'Hello Nico!';
              }]);
            })
          ;
        })
      ;

isEmpty().

test
  .string('')
    .isEmpty()
  .exception(function(){
    test.string(str).isEmpty();
  })
;

isNotEmpty().

test
  .string('a')
    .isNotEmpty()
  .exception(function(){
    test.string('').isNotEmpty();
  })
;

hasLength(expected).

test
  .string('Hello Nico')
    .hasLength(10)
  .exception(function(){
    test.string('abc').hasLength(4);
  })
;

hasNotLength(expected).

test
  .string('Hello Nico')
    .hasNotLength(11)
  .exception(function(){
    test.string('abc').hasNotLength(3);
  })
;

hasValue(expected).

test
  .string('Hello, Nico!')
    .hasValue('Nico')
  .exception(function(){
    test.string('Hello').hasValue('hello');
  })
;

notHasValue(expected).

test
  .string('Hello, Nico!')
    .notHasValue('Bye')
  .exception(function(){
    test.string('Hello').notHasValue('Hello');
  })
;

hasValues(expected).

test
  .string('Hello Nico!')
    .hasValues(['Hello', 'Nico'])
  .exception(function(){
    test.string('Hello Nico!').hasValues(['Hi', 'Nico']);
  })
;

notHasValues(expected).

test
  .string('Sarah Connor ?')
    .notHasValues(['next', 'door'])
  .exception(function(){
    test.string('Hello Nico!').notHasValues(['Hi', 'Nico']);
  })
;

contains(expected [, ...]).

test
  .string('hello boy')
    .contains('boy')
  .string('KISS principle : Keep it Simple, Stupid')
    .contains(['Simple'], ['principle'], [':'])
  .exception(function(){
    test.string('Hello').contains('hello');
  })
;

notContains(expected [, ...]).

test
  .string('hello boy')
    .notContains('bye')
  .exception(function(){
    test.string('Hello').notContains('Hello');
  })
;

startsWith(str).

test
  .string('foobar')
    .startsWith('foo')
  .exception(function(){
    test.string('Hello the world').startsWith('world');
  })
;

notStartsWith(str).

test
  .string('foobar')
    .notStartsWith('bar')
  .exception(function(){
    test.string('Hello the world').notStartsWith('Hello');
  })
;

endsWith(str).

test
  .string('foobar')
    .endsWith('bar')
  .exception(function(){
    test.string('Hello the world').endsWith('Hello');
  })
;

notEndsWith(str).

test
  .string('foobar')
    .notEndsWith('foo')
  .exception(function(){
    test.string('Hello the world').notEndsWith('world');
  })
;