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.
ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
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.
ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isNot('hello world !');
See also -
isIdenticalTo(expected)
-
Assert that the
actual
string is identical to (===
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
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.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isNotIdenticalTo('hello world !');
See also -
isEqualTo(expected)
-
Assert that the
actual
string is equal to (==
) theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isEqualTo('Hello world !');
See also -
isNotEqualTo(expected)
-
Assert that the
actual
string is not equal to (!=
) theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var str = 'Hello world !'; test.string(str).isNotEqualTo('hello world !');
See also -
match(expected)
-
Assert
actual
string to match theexpected
value.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType 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
actual
string to not match theexpected
value.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ReturnsType 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
ReturnsType 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
ReturnsType 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
actual
string to match eachexpected
value.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected matches for each
ReturnsType Description ObjectThe current instance
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 severalexpected
value.ParametersName Type Description expected ArrayStringNumberRegExpfunctionExpected value that must not match
ReturnsType Description ObjectThe current instance
test.string('Hello World').notMatchEach([/foo/i, 'bad word', function(it){ return it === 'Bye'; }]);
See also -
isEmpty()
-
Assert that the
actual
string is empty.ReturnsType Description ObjectThe current instance
test.string('').isEmpty();
See also -
isNotEmpty()
-
Assert that the
actual
string is not empty.ReturnsType Description ObjectThe current instance
test.string('a').isNotEmpty();
See also -
hasLength(expected)
-
Assert that the
actual
string has a length equal toexpected
number.ParametersName Type Description expected numberExpected length
ReturnsType Description ObjectThe current instance
test.string('Hello Nico').hasLength(10);
See also -
hasNotLength(expected)
-
Assert that the
actual
string has not a length equal toexpected
number.ParametersName Type Description expected numberExpected length
ReturnsType Description ObjectThe current instance
test.string('Hello Nico').hasNotLength(11);
See also -
hasValue(expected)
-
Assert that the
actual
tested string hasexpected
value.Is checked with strict equals
(===)
.ParametersName Type Description expected mixedThe expected value
ReturnsType Description ObjectThe current instance
test.string('Hello, Nico!').hasValue('Nico');
See also -
notHasValue(expected)
-
Assert that the
actual
tested string not hasexpected
value.Is checked with strict equals
(!==)
.ParametersName Type Description expected mixedThe expected value
ReturnsType Description ObjectThe current instance
test.string('Hello, Nico!').notHasValue('Bye');
See also -
hasValues(expected)
-
Assert that the
actual
tested string has severalexpected
values passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ReturnsType Description ObjectThe current instance
test.string('Hello Nico!').hasValues(['Hello', 'Nico']);
See also -
notHasValues(expected)
-
Assert that the
actual
tested string not has severalexpected
values passed in an array of expected values.ParametersName Type Description expected ArrayAn array of expected values
ReturnsType Description ObjectThe current instance
test.string('Sarah Connor ?').notHasValues(['next', 'door']);
See also -
contains(expected)
-
Assert that the
actual
string to contain something(===)
toexpected
.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ReturnsType 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
actual
string to not contain something(!==)
toexpected
.ParametersName Type Argument Description expected mixedrepeatable One or more expected value.
ReturnsType Description ObjectThe current instance
test .string('hello boy') .notContains('bye') .exception(function(){ test.string('Hello').notContains('Hello'); }) ;
See also -
startsWith(str)
-
Assert that the
actual
string starts withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.string('foobar').startsWith('foo');
See also -
notStartsWith(str)
-
Assert that the
actual
string not starts withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.string('foobar').notStartsWith('bar');
See also -
endsWith(str)
-
Assert that the
actual
string ends withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.string('foobar').endsWith('bar');
See also -
notEndsWith(str)
-
Assert that the
actual
string not ends withstr
.ParametersName Type Description str StringExpected
string
valueReturnsType Description ObjectThe current instance
test.string('foobar').notEndsWith('foo');
See also