string

String asserter.

Assert that the actual value is a string (using .isString() assertion). The string() asserter provides adapted assertions for works on a string.

See also the spec of "string" asserter for more examples.

Example

test.string(actual);

Methods

is(expected)


Assert actual string equality.

For most parts it asserts strict equality (===), but:

  • String objects are compared to string literals.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
var str = 'Hello world !';

test.string(str).is('Hello world !');

See also

isNot(expected)


Assert actual string to the negative equality.

For most parts it asserts strict (!==), but:

  • String objects are compared to string literals.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
var str = 'Hello world !';

test.string(str).isNot('hello world !');

See also

isIdenticalTo(expected)


Assert that the actual string is identical to (===) expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
var str = 'Hello world !';

test.string(str).isIdenticalTo('Hello world !');

See also

isNotIdenticalTo(expected)


Assert that the actual string is not identical to (!==) expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
var str = 'Hello world !';

test.string(str).isNotIdenticalTo('hello world !');

See also

isEqualTo(expected)


Assert that the actual string is equal to (==) the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
var str = 'Hello world !';

test.string(str).isEqualTo('Hello world !');

See also

isNotEqualTo(expected)


Assert that the actual string is not equal to (!=) the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
var str = 'Hello world !';

test.string(str).isNotEqualTo('hello world !');

See also

match(expected)


Assert actual string to match the expected value.

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
// 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';
});

See also

notMatch(expected)


Assert actual string to not match the expected value.

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected value that must not match

Returns
Type Description
Object

The current instance

Example
test
  .string('foobar')
    .notMatch('some value')
    .notMatch(/[foo]+bazzz$/)

  .string('foo')
    .notMatch(function(it){
      return it === 'bar';
    })
;

See also

isValid(expected)


Alias of match().

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
// 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';
});

See also

isNotValid(expected)


Alias of notMatch().

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
test
  .string('foobar')
    .isNotValid('some value')
    .isNotValid(/[foo]+bazzz$/)

  .string('foo')
    .isNotValid(function(it){
      return it === 'bar';
    })
 ;

See also

matchEach(expected)


Assert actual string to match each expected value.

Parameters
Name Type Description
expected
Array
String
Number
RegExp
function

Expected matches for each

Returns
Type Description
Object

The current instance

Example
test.string('Hello Nico!').matchEach([/hello/i, 'Nico', function(it){
  return it === 'Hello Nico!';
}]);

See also

notMatchEach(expected)


Assert actual string to not match one or several expected value.

Parameters
Name Type Description
expected
Array
String
Number
RegExp
function

Expected value that must not match

Returns
Type Description
Object

The current instance

Example
test.string('Hello World').notMatchEach([/foo/i, 'bad word', function(it){
  return it === 'Bye';
}]);

See also

isEmpty()


Assert that the actual string is empty.

Returns
Type Description
Object

The current instance

Example
test.string('').isEmpty();

See also

isNotEmpty()


Assert that the actual string is not empty.

Returns
Type Description
Object

The current instance

Example
test.string('a').isNotEmpty();

See also

hasLength(expected)


Assert that the actual string has a length equal to expected number.

Parameters
Name Type Description
expected
number

Expected length

Returns
Type Description
Object

The current instance

Example
test.string('Hello Nico').hasLength(10);

See also

hasNotLength(expected)


Assert that the actual string has not a length equal to expected number.

Parameters
Name Type Description
expected
number

Expected length

Returns
Type Description
Object

The current instance

Example
test.string('Hello Nico').hasNotLength(11);

See also

hasValue(expected)


Assert that the actual tested string has expected value.

Is checked with strict equals (===).

Parameters
Name Type Description
expected
mixed

The expected value

Returns
Type Description
Object

The current instance

Example
test.string('Hello, Nico!').hasValue('Nico');

See also

notHasValue(expected)


Assert that the actual tested string not has expected value.

Is checked with strict equals (!==).

Parameters
Name Type Description
expected
mixed

The expected value

Returns
Type Description
Object

The current instance

Example
test.string('Hello, Nico!').notHasValue('Bye');

See also

hasValues(expected)


Assert that the actual tested string has several expected values passed in an array of expected values.

Parameters
Name Type Description
expected
Array

An array of expected values

Returns
Type Description
Object

The current instance

Example
test.string('Hello Nico!').hasValues(['Hello', 'Nico']);

See also

notHasValues(expected)


Assert that the actual tested string not has several expected values passed in an array of expected values.

Parameters
Name Type Description
expected
Array

An array of expected values

Returns
Type Description
Object

The current instance

Example
test.string('Sarah Connor ?').notHasValues(['next', 'door']);

See also

contains(expected)


Assert that the actual string to contain something (===) to expected.

Parameters
Name Type Argument Description
expected
mixed
repeatable 

One or more expected value.

Returns
Type Description
Object

The current instance

Example
test
 .string('hello boy')
   .contains('boy')

 .string('KISS principle : Keep it Simple, Stupid')
   .contains('Simple', 'principle', ':')

 .exception(function(){
   test.string('Hello').contains('hello');
 })
 ;

See also

notContains(expected)


Assert that the actual string to not contain something (!==) to expected.

Parameters
Name Type Argument Description
expected
mixed
repeatable 

One or more expected value.

Returns
Type Description
Object

The current instance

Example
test
 .string('hello boy')
   .notContains('bye')

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

See also

startsWith(str)


Assert that the actual string starts with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.string('foobar').startsWith('foo');

See also

notStartsWith(str)


Assert that the actual string not starts with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.string('foobar').notStartsWith('bar');

See also

endsWith(str)


Assert that the actual string ends with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.string('foobar').endsWith('bar');

See also

notEndsWith(str)


Assert that the actual string not ends with str.

Parameters
Name Type Description
str
String

Expected string value

Returns
Type Description
Object

The current instance

Example
test.string('foobar').notEndsWith('foo');

See also