regexp

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.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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 (==) the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
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 (!=) the expected value.

Parameters
Name Type Description
expected
mixed

Expected value

Returns
Type Description
Object

The current instance

Example
var regexp = new RegExp(/[a-z]/);

test.regexp(regexp).isNotEqualTo(new RegExp(/[a-z]/));

See also

match(expected)


Assert actual RegExp to match the expected value.

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
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 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
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().

Parameters
Name Type Description
expected
String
Number
RegExp
function

Expected matches

Returns
Type Description
Object

The current instance

Example
var 
  regexp = new RegExp(/[a-z]/),
  ref = regexp
;

test.regexp(regexp).isValid(function(reg){
  return reg === ref;
});

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
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 enumerable property. It will fail if the actual value lacks the property 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().

Parameters
Name Type Description
property
String

The property name

Returns
Type Description
Object

The current instance

Example
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-enumerable property. It will fail if the actual value lacks the property 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().

Parameters
Name Type Description
property
String

The property name

Returns
Type Description
Object

The current instance

Example
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 with Object.isFrozen.

Returns
Type Description
Object

The current instance

Example
var regexp = new RegExp(/[a-z]/);
Object.freeze(regexp);

test.regexp(regexp).isFrozen();

See also

isNotFrozen()


Assert that the actual RegExp is not frozen with Object.isFrozen.

Returns
Type Description
Object

The current instance

Example
var regexp = new RegExp(/[a-z]/);

test.regexp(regexp).isNotFrozen();

See also

hasProperty(property, value)


Assert that the actual tested RegExp has property. Optionally assert it equals (===) to value argument.

Takes inherited properties into account. To not do so, see hasOwnProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
test.regexp(/[a-z]/)
  .hasProperty('lastIndex')
  .hasProperty('constructor')
;

See also

hasNotProperty(property, value)


Assert that the actual tested RegExp has not a property. Optionally assert it not equals (!==) to value argument.

Takes inherited properties into account. To not do so, see hasNotOwnProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
test.regexp(/[a-z]/).hasNotProperty('foobar');

See also

hasOwnProperty(property, value)


Assert that the actual tested RegExp has own property. Optionally assert it equals (===) to value argument.

Does not take inherited properties into account. To do so, see hasProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
test.regexp(/[a-z]/)
  .hasOwnProperty('lastIndex');

See also

hasNotOwnProperty(property, value)


Assert that the actual tested RegExp has not own property. Optionally assert it not equals (!==) to value argument.

Does not take inherited properties into account. To do so, see hasNotProperty().

Parameters
Name Type Argument Description
property
String

The property name

value
mixed
optional 

The property value

Returns
Type Description
Object

The current instance

Example
test.regexp(/[a-z]/)
  .hasNotOwnProperty('constructor');

See also

hasKey(key, value)


Alias of hasProperty()

Assert that the actual tested RegExp has a key. Optionally assert it equals (===) to value argument.

Takes inherited properties into account. To not do so, see hasOwnProperty().

Parameters
Name Type Argument Description
key
String

The key name

value
mixed
optional 

The key value

Returns
Type Description
Object

The current instance

Example
test.regexp(/[a-z]/)
  .hasKey('lastIndex')
  .hasKey('constructor')
;

See also

notHasKey(key, value)


Alias of hasNotProperty()

Assert that the actual tested RegExp has not a key. Optionally assert it not equals (!==) to value argument.

Takes inherited properties into account. To not do so, see hasNotOwnProperty().

Parameters
Name Type Argument Description
key
String

The key name

value
mixed
optional 

The key value

Returns
Type Description
Object

The current instance

Example
test.regexp(/[a-z]/).notHasKey('foobar');

See also