Documentation Home
This page is for an older version of Jasmine (5.2).
The current stable version of Jasmine is: 5.4. You can also look at the docs for the next release: Edge

Namespace: asymmetricEqualityTesters

asymmetricEqualityTesters

Asymmetric equality testers allow for non-exact matching in matchers that use Jasmine's deep value equality semantics, such as toEqual, toContain, and toHaveBeenCalledWith.

Example

const someComplexObject = {
  foo: 'bar',
  baz: 'a string that contains "something"',
  qux: 'whatever'
};
// Passes.
expect(someComplexObject).toEqual(jasmine.objectContaining({
  foo: 'bar',
  baz: jasmine.stringContaining('something')
});

Methods

(static) jasmine.any(clazz)

Get an AsymmetricEqualityTester that will succeed if the actual value being compared is an instance of the specified class/constructor.

Parameters:
Name Type Description
clazz Constructor

The constructor to check against.

Since:
  • 1.3.0

(static) jasmine.anything()

Get an AsymmetricEqualityTester that will succeed if the actual value being compared is not null and not undefined.

Since:
  • 2.2.0

(static) jasmine.arrayContaining(sample)

Get an AsymmetricEqualityTester that will succeed if the actual value is an Array that contains at least the elements in the sample.

Parameters:
Name Type Description
sample Array
Since:
  • 2.2.0

(static) jasmine.arrayWithExactContents(sample)

Get an AsymmetricEqualityTester that will succeed if the actual value is an Array that contains all of the elements in the sample in any order.

Parameters:
Name Type Description
sample Array
Since:
  • 2.8.0

(static) jasmine.empty()

Get an AsymmetricEqualityTester that will succeed if the actual value being compared is empty.

Since:
  • 3.1.0

(static) jasmine.falsy()

Get an AsymmetricEqualityTester that will succeed if the actual value being compared is null, undefined, 0, false or anything falsy.

Since:
  • 3.1.0

(static) jasmine.is(sample)

Get an AsymmetricEqualityTester that passes if the actual value is the same as the sample as determined by the === operator.

Parameters:
Name Type Description
sample Object

The value to compare the actual to.

(static) jasmine.mapContaining(sample)

Get an AsymmetricEqualityTester that will succeed if every key/value pair in the sample passes the deep equality comparison with at least one key/value pair in the actual value being compared

Parameters:
Name Type Description
sample Map

The subset of items that must be in the actual.

Since:
  • 3.5.0

(static) jasmine.notEmpty()

Get an AsymmetricEqualityTester that will succeed if the actual value being compared is not empty.

Since:
  • 3.1.0

(static) jasmine.objectContaining(sample)

Get an AsymmetricEqualityTester that will succeed if the actual value being compared contains at least the specified keys and values.

Parameters:
Name Type Description
sample Object

The subset of properties that must be in the actual.

Since:
  • 1.3.0

(static) jasmine.setContaining(sample)

Get an AsymmetricEqualityTester that will succeed if every item in the sample passes the deep equality comparison with at least one item in the actual value being compared

Parameters:
Name Type Description
sample Set

The subset of items that must be in the actual.

Since:
  • 3.5.0

(static) jasmine.stringContaining(expected)

Get an AsymmetricEqualityTester that will succeed if the actual value is a String that contains the specified String.

Parameters:
Name Type Description
expected String
Since:
  • 3.10.0

(static) jasmine.stringMatching(expected)

Get an AsymmetricEqualityTester that will succeed if the actual value is a String that matches the RegExp or String.

Parameters:
Name Type Description
expected RegExp | String
Since:
  • 2.2.0

(static) jasmine.truthy()

Get an AsymmetricEqualityTester that will succeed if the actual value being compared is true or anything truthy.

Since:
  • 3.1.0