RegExp asserter.
Assert that actual
value is an instance of RegExp
(using .isRegExp()
assertion).
The regexp()
asserter provides adapted assertions for works on an instance of RegExp
.
See also the spec of "regexp" asserter for more examples.
Example
test.regexp(actual);
Methods
-
is(expected)
-
Assert
actual
RegExp
equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict equality (
===
), but:RegExp
objects are compared by their pattern and flags.
Does not coerce types so mismatching types fail. Inherited enumerable properties are also taken into account.
ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); test.regexp(regexp).is(new RegExp(/[a-z]/));
See also -
isNot(expected)
-
Assert
actual
RegExp
to the negative equality by content and if possible, recursively.Also handles circular and self-referential objects.
For most parts it asserts strict (
!==
), but:RegExp
objects are compared by their pattern and flags.
Does not coerce types so mismatching types fail. Inherited enumerable properties are also taken into account.
ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); test.regexp(regexp).isNot(new RegExp(/[A-Z]/));
See also -
isIdenticalTo(expected)
-
Assert that the
actual
RegExp
is identical to (===
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/), ref = regexp ; test.regexp(regexp).isIdenticalTo(ref);
See also -
isNotIdenticalTo(expected)
-
Assert that the
actual
RegExp
is not identical to (!==
)expected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); test.regexp(regexp).isNotIdenticalTo(new RegExp(/[a-z]/));
See also -
isEqualTo(expected)
-
Assert that the
actual
RegExp
is equal to (==
) theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/), ref = regexp ; test.regexp(regexp).isEqualTo(ref);
See also -
isNotEqualTo(expected)
-
Assert that the
actual
RegExp
is not equal to (!=
) theexpected
value.ParametersName Type Description expected mixedExpected value
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); test.regexp(regexp).isNotEqualTo(new RegExp(/[a-z]/));
See also -
match(expected)
-
Assert
actual
RegExp
to match theexpected
value.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/), ref = regexp ; test.regexp(regexp).match(function(reg){ return reg === ref; });
See also -
notMatch(expected)
-
Assert
actual
RegExp
to not match theexpected
value.ParametersName Type Description expected StringNumberRegExpfunctionExpected value that must not match
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/), ref = regexp ; test.regexp(regexp).notMatch(function(actual){ var reg = new RegExp(/[a-z]/); return reg === ref || reg === actual; });
See also -
isValid(expected)
-
Alias of
match()
.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/), ref = regexp ; test.regexp(regexp).isValid(function(reg){ return reg === ref; });
See also -
isNotValid(expected)
-
Alias of
notMatch()
.ParametersName Type Description expected StringNumberRegExpfunctionExpected matches
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/), ref = regexp ; test.regexp(regexp).isNotValid(function(actual){ var reg = new RegExp(/[a-z]/); return reg === ref || reg === actual; });
See also -
isEnumerable(property)
-
Assert that the
actual
RegExp
has an enumerableproperty
. It will fail if theactual
value lacks theproperty
entirely.This also checks inherited properties in the prototype chain, something which
Object.prototype.propertyIsEnumerable
itself does not do.For checking if a property exists and is non-enumerable, see
isNotEnumerable()
.ParametersName Type Description property StringThe property name
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); // define an enumerable property Object.defineProperty(regexp, 'myCustom', { enumerable: true, value: 'static' }); test.regexp(regexp).isEnumerable('myCustom');
See also -
isNotEnumerable(property)
-
Assert that the
actual
RegExp
has a non-enumerableproperty
. It will fail if theactual
value lacks theproperty
entirely.This also checks inherited properties in the prototype chain, something which
Object.prototype.propertyIsEnumerable
itself does not do.It's the inverse of
isEnumerable()
.ParametersName Type Description property StringThe property name
ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); // define a non-enumerable property Object.defineProperty(regexp, 'myCustom', { enumerable: false, value: 'static' }); test .regexp(regexp) .isNotEnumerable('myCustom') .isNotEnumerable('lastIndex') .isNotEnumerable('ignoreCase') .isNotEnumerable('multiline') ;
See also -
isFrozen()
-
Assert that the
actual
RegExp
is frozen withObject.isFrozen
.ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); Object.freeze(regexp); test.regexp(regexp).isFrozen();
See also -
isNotFrozen()
-
Assert that the
actual
RegExp
is not frozen withObject.isFrozen
.ReturnsType Description ObjectThe current instance
var regexp = new RegExp(/[a-z]/); test.regexp(regexp).isNotFrozen();
See also -
hasProperty(property, value)
-
Assert that the
actual
testedRegExp
hasproperty
. Optionally assert it equals(===)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasOwnProperty()
.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test.regexp(/[a-z]/) .hasProperty('lastIndex') .hasProperty('constructor') ;
See also -
hasNotProperty(property, value)
-
Assert that the
actual
testedRegExp
has not aproperty
. Optionally assert it not equals(!==)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasNotOwnProperty()
.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test.regexp(/[a-z]/).hasNotProperty('foobar');
See also -
hasOwnProperty(property, value)
-
Assert that the
actual
testedRegExp
has ownproperty
. Optionally assert it equals(===)
tovalue
argument.Does not take inherited properties into account. To do so, see
hasProperty()
.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test.regexp(/[a-z]/) .hasOwnProperty('lastIndex');
See also -
hasNotOwnProperty(property, value)
-
Assert that the
actual
testedRegExp
has not ownproperty
. Optionally assert it not equals(!==)
tovalue
argument.Does not take inherited properties into account. To do so, see
hasNotProperty()
.ParametersName Type Argument Description property StringThe property name
value mixedoptional The property value
ReturnsType Description ObjectThe current instance
test.regexp(/[a-z]/) .hasNotOwnProperty('constructor');
See also -
hasKey(key, value)
-
Alias of hasProperty()
Assert that the
actual
testedRegExp
has akey
. Optionally assert it equals(===)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasOwnProperty()
.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ReturnsType Description ObjectThe current instance
test.regexp(/[a-z]/) .hasKey('lastIndex') .hasKey('constructor') ;
See also -
notHasKey(key, value)
-
Alias of hasNotProperty()
Assert that the
actual
testedRegExp
has not akey
. Optionally assert it not equals(!==)
tovalue
argument.Takes inherited properties into account. To not do so, see
hasNotOwnProperty()
.ParametersName Type Argument Description key StringThe key name
value mixedoptional The key value
ReturnsType Description ObjectThe current instance
test.regexp(/[a-z]/).notHasKey('foobar');
See also