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

Namespace: async-matchers

async-matchers

Asynchronous matchers.

Members

not :async-matchers

Invert the matcher following this expectAsync

Type:
Examples
await expectAsync(myPromise).not.toBeResolved();
return expectAsync(myPromise).not.toBeResolved();

Methods

(async) toBeRejected()

Expect a promise to be rejected.

Since:
  • 3.1.0
Examples
await expectAsync(aPromise).toBeRejected();
return expectAsync(aPromise).toBeRejected();

(async) toBeRejectedWith(expected)

Expect a promise to be rejected with a value equal to the expected, using deep equality comparison.

Parameters:
Name Type Description
expected Object

Value that the promise is expected to be rejected with

Since:
  • 3.3.0
Examples
await expectAsync(aPromise).toBeRejectedWith({prop: 'value'});
return expectAsync(aPromise).toBeRejectedWith({prop: 'value'});

(async) toBeRejectedWithError(expectedopt, messageopt)

Expect a promise to be rejected with a value matched to the expected

Parameters:
Name Type Attributes Description
expected Error <optional>

Error constructor the object that was thrown needs to be an instance of. If not provided, Error will be used.

message RegExp | String <optional>

The message that should be set on the thrown Error

Since:
  • 3.5.0
Example
await expectAsync(aPromise).toBeRejectedWithError(MyCustomError, 'Error message');
await expectAsync(aPromise).toBeRejectedWithError(MyCustomError, /Error message/);
await expectAsync(aPromise).toBeRejectedWithError(MyCustomError);
await expectAsync(aPromise).toBeRejectedWithError('Error message');
return expectAsync(aPromise).toBeRejectedWithError(/Error message/);

(async) toBeResolved()

Expect a promise to be resolved.

Since:
  • 3.1.0
Examples
await expectAsync(aPromise).toBeResolved();
return expectAsync(aPromise).toBeResolved();

(async) toBeResolvedTo(expected)

Expect a promise to be resolved to a value equal to the expected, using deep equality comparison.

Parameters:
Name Type Description
expected Object

Value that the promise is expected to resolve to

Since:
  • 3.1.0
Examples
await expectAsync(aPromise).toBeResolvedTo({prop: 'value'});
return expectAsync(aPromise).toBeResolvedTo({prop: 'value'});

withContext(message) → {async-matchers}

Add some context for an expectAsync

Parameters:
Name Type Description
message String

Additional context to show when the async matcher fails

Since:
  • 3.3.0
Returns:
Type
async-matchers