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
actualstring equality.For most parts it asserts strict equality (
===), but:Stringobjects are compared to string literals.
ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).is('Hello world !');
See also -
isNot(expected)
-
Assert
actualstring to the negative equality.For most parts it asserts strict (
!==), but:Stringobjects are compared to string literals.
ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isNot('hello world !');
See also -
isIdenticalTo(expected)
-
Assert that the
actualstring is identical to (===)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isIdenticalTo('Hello world !');
See also -
isNotIdenticalTo(expected)
-
Assert that the
actualstring is not identical to (!==)expectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isNotIdenticalTo('hello world !');
See also -
isEqualTo(expected)
-
Assert that the
actualstring is equal to (==) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isEqualTo('Hello world !');
See also -
isNotEqualTo(expected)
-
Assert that the
actualstring is not equal to (!=) theexpectedvalue.ParametersName Type Description expected mixedExpected value
ExampleReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isNotEqualTo('hello world !');
See also -
match(expected)
-
Assert
actualstring to match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
// 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
actualstring to not match theexpectedvalue.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
test .string('foobar') .notMatch('some value') .notMatch(/[foo]+bazzz$/) .string('foo') .notMatch(function(it){ return it === 'bar'; }) ;
See also -
isValid(expected)
-
Alias of
match().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
// 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().ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ExampleReturnsType Description ObjectThe current instance
test .string('foobar') .isNotValid('some value') .isNotValid(/[foo]+bazzz$/) .string('foo') .isNotValid(function(it){ return it === 'bar'; }) ;
See also -
matchEach(expected)
-
Assert
actualstring to match eachexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected matches for each
ExampleReturnsType Description ObjectThe current instance
test.string('Hello Nico!').matchEach([/hello/i, 'Nico', function(it){ return it === 'Hello Nico!'; }]);
See also -
notMatchEach(expected)
-
Assert
actualstring to not match one or severalexpectedvalue.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected value that must not match
ExampleReturnsType Description ObjectThe current instance
test.string('Hello World').notMatchEach([/foo/i, 'bad word', function(it){ return it === 'Bye'; }]);
See also -
isEmpty()
-
Assert that the
actualstring is empty.ExampleReturnsType Description ObjectThe current instance
test.string('').isEmpty();
See also -
isNotEmpty()
-
Assert that the
actualstring is not empty.ExampleReturnsType Description ObjectThe current instance
test.string('a').isNotEmpty();
See also -
hasLength(expected)
-
Assert that the
actualstring has a length equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test.string('Hello Nico').hasLength(10);
See also -
hasNotLength(expected)
-
Assert that the
actualstring has not a length equal toexpectednumber.ParametersName Type Description expected numberExpected length
ExampleReturnsType Description ObjectThe current instance
test.string('Hello Nico').hasNotLength(11);
See also -
hasValue(expected)
-
Assert that the
actualtested string hasexpectedvalue.Is checked with strict equals
(===).ParametersName Type Description expected mixedThe expected value
ExampleReturnsType Description ObjectThe current instance
test.string('Hello, Nico!').hasValue('Nico');
See also -
notHasValue(expected)
-
Assert that the
actualtested string not hasexpectedvalue.Is checked with strict equals
(!==).ParametersName Type Description expected mixedThe expected value
ExampleReturnsType Description ObjectThe current instance
test.string('Hello, Nico!').notHasValue('Bye');
See also -
hasValues(expected)
-
Assert that the
actualtested string has severalexpectedvalues passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ExampleReturnsType Description ObjectThe current instance
test.string('Hello Nico!').hasValues(['Hello', 'Nico']);
See also -
notHasValues(expected)
-
Assert that the
actualtested string not has severalexpectedvalues passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ExampleReturnsType Description ObjectThe current instance
test.string('Sarah Connor ?').notHasValues(['next', 'door']);
See also -
contains(expected)
-
Assert that the
actualstring to contain something(===)toexpected.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ExampleReturnsType Description ObjectThe current instance
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
actualstring to not contain something(!==)toexpected.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ExampleReturnsType Description ObjectThe current instance
test .string('hello boy') .notContains('bye') .exception(function(){ test.string('Hello').notContains('Hello'); }) ;
See also -
startsWith(str)
-
Assert that the
actualstring starts withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.string('foobar').startsWith('foo');
See also -
notStartsWith(str)
-
Assert that the
actualstring not starts withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.string('foobar').notStartsWith('bar');
See also -
endsWith(str)
-
Assert that the
actualstring ends withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.string('foobar').endsWith('bar');
See also -
notEndsWith(str)
-
Assert that the
actualstring not ends withstr.ParametersName Type Description str StringExpected
stringvalueExampleReturnsType Description ObjectThe current instance
test.string('foobar').notEndsWith('foo');
See also

