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

Global

Methods

afterAll(functionopt, timeoutopt)

Run some shared teardown once after all of the specs in the describe are run.

Note: Be careful, sharing the teardown from a afterAll makes it easy to accidentally leak state between your specs so that they erroneously pass or fail.

Parameters:
Name Type Attributes Default Description
function implementationCallback <optional>

Function that contains the code to teardown your specs.

timeout Int <optional>
jasmine.DEFAULT_TIMEOUT_INTERVAL

Custom timeout for an async afterAll.

Since:
  • 2.1.0
See:

afterEach(functionopt, timeoutopt)

Run some shared teardown after each of the specs in the describe in which it is called.

Parameters:
Name Type Attributes Default Description
function implementationCallback <optional>

Function that contains the code to teardown your specs.

timeout Int <optional>
jasmine.DEFAULT_TIMEOUT_INTERVAL

Custom timeout for an async afterEach.

Since:
  • 1.3.0
See:

beforeAll(functionopt, timeoutopt)

Run some shared setup once before all of the specs in the describe are run.

Note: Be careful, sharing the setup from a beforeAll makes it easy to accidentally leak state between your specs so that they erroneously pass or fail.

Parameters:
Name Type Attributes Default Description
function implementationCallback <optional>

Function that contains the code to setup your specs.

timeout Int <optional>
jasmine.DEFAULT_TIMEOUT_INTERVAL

Custom timeout for an async beforeAll.

Since:
  • 2.1.0
See:

beforeEach(functionopt, timeoutopt)

Run some shared setup before each of the specs in the describe in which it is called.

Parameters:
Name Type Attributes Default Description
function implementationCallback <optional>

Function that contains the code to setup your specs.

timeout Int <optional>
jasmine.DEFAULT_TIMEOUT_INTERVAL

Custom timeout for an async beforeEach.

Since:
  • 1.3.0
See:

describe(description, specDefinitions)

Create a group of specs (often called a suite).

Calls to describe can be nested within other calls to compose your suite as a tree.

Parameters:
Name Type Description
description String

Textual description of the group

specDefinitions function

Function for Jasmine to invoke that will define inner suites and specs

Since:
  • 1.3.0

expect(actual) → {matchers}

Create an expectation for a spec.

Parameters:
Name Type Description
actual Object

Actual computed value to test expectations against.

Since:
  • 1.3.0
Returns:
Type
matchers

expectAsync(actual) → {async-matchers}

Create an asynchronous expectation for a spec. Note that the matchers that are provided by an asynchronous expectation all return promises which must be either returned from the spec or waited for using await in order for Jasmine to associate them with the correct spec.

Parameters:
Name Type Description
actual Object

Actual computed value to test expectations against.

Since:
  • 3.3.0
Returns:
Type
async-matchers
Examples
await expectAsync(somePromise).toBeResolved();
return expectAsync(somePromise).toBeResolved();

fail(erroropt)

Explicitly mark a spec as failed.

Parameters:
Name Type Attributes Description
error String | Error <optional>

Reason for the failure.

Since:
  • 2.1.0

fdescribe(description, specDefinitions)

A focused describe

If suites or specs are focused, only those that are focused will be executed

Parameters:
Name Type Description
description String

Textual description of the group

specDefinitions function

Function for Jasmine to invoke that will define inner suites and specs

Since:
  • 2.1.0
See:

fit(description, testFunction, timeoutopt)

A focused it

If suites or specs are focused, only those that are focused will be executed.

Parameters:
Name Type Attributes Default Description
description String

Textual description of what this spec is checking.

testFunction implementationCallback

Function that contains the code of your test.

timeout Int <optional>
jasmine.DEFAULT_TIMEOUT_INTERVAL

Custom timeout for an async spec.

Since:
  • 2.1.0
See:

it(description, testFunctionopt, timeoutopt)

Define a single spec. A spec should contain one or more expectations that test the state of the code.

A spec whose expectations all succeed will be passing and a spec with any failures will fail. The name it is a pronoun for the test target, not an abbreviation of anything. It makes the spec more readable by connecting the function name it and the argument description as a complete sentence.

Parameters:
Name Type Attributes Default Description
description String

Textual description of what this spec is checking

testFunction implementationCallback <optional>

Function that contains the code of your test. If not provided the test will be pending.

timeout Int <optional>
jasmine.DEFAULT_TIMEOUT_INTERVAL

Custom timeout for an async spec.

Since:
  • 1.3.0
See:

pending(messageopt)

Mark a spec as pending, expectation results will be ignored.

Parameters:
Name Type Attributes Description
message String <optional>

Reason the spec is pending.

Since:
  • 2.0.0

setSpecProperty(key, value)

Sets a user-defined property that will be provided to reporters as part of the properties field of SpecResult

Parameters:
Name Type Description
key String

The name of the property

value *

The value of the property

Since:
  • 3.6.0

setSuiteProperty(key, value)

Sets a user-defined property that will be provided to reporters as part of the properties field of SuiteResult

Parameters:
Name Type Description
key String

The name of the property

value *

The value of the property

Since:
  • 3.6.0

spyOn(obj, methodName) → {Spy}

Install a spy onto an existing object.

Parameters:
Name Type Description
obj Object

The object upon which to install the Spy.

methodName String

The name of the method to replace with a Spy.

Since:
  • 1.3.0
Returns:
Type
Spy

spyOnAllFunctions(obj, includeNonEnumerable) → {Object}

Installs spies on all writable and configurable properties of an object.

Parameters:
Name Type Description
obj Object

The object upon which to install the Spys

includeNonEnumerable boolean

Whether or not to add spies to non-enumerable properties

Since:
  • 3.2.1
Returns:

the spied object

Type
Object

spyOnProperty(obj, propertyName, accessTypeopt) → {Spy}

Install a spy on a property installed with Object.defineProperty onto an existing object.

Parameters:
Name Type Attributes Default Description
obj Object

The object upon which to install the Spy

propertyName String

The name of the property to replace with a Spy.

accessType String <optional>
get

The access type (get|set) of the property to Spy on.

Since:
  • 2.6.0
Returns:
Type
Spy

xdescribe(description, specDefinitions)

A temporarily disabled describe

Specs within an xdescribe will be marked pending and not executed

Parameters:
Name Type Description
description String

Textual description of the group

specDefinitions function

Function for Jasmine to invoke that will define inner suites and specs

Since:
  • 1.3.0

xit(description, testFunctionopt)

A temporarily disabled it

The spec will report as pending and will not be executed.

Parameters:
Name Type Attributes Description
description String

Textual description of what this spec is checking.

testFunction implementationCallback <optional>

Function that contains the code of your test. Will not be executed.

Since:
  • 1.3.0

Type Definitions

Expectation

Properties:
Name Type Description
matcherName String

The name of the matcher that was executed for this expectation.

message String

The failure message for the expectation.

stack String

The stack trace for the failure if available.

passed Boolean

Whether the expectation passed or failed.

expected Object

If the expectation failed, what was the expected value.

actual Object

If the expectation failed, what actual value was produced.

implementationCallback(doneopt)

Callback passed to parts of the Jasmine base interface.

By default Jasmine assumes this function completes synchronously. If you have code that you need to test asynchronously, you can declare that you receive a done callback, return a Promise, or use the async keyword if it is supported in your environment.

Parameters:
Name Type Attributes Description
done function <optional>

Used to specify to Jasmine that this callback is asynchronous and Jasmine should wait until it has been called before moving on.

Returns:

Optionally return a Promise instead of using done to cause Jasmine to wait for completion.

JasmineDoneInfo

Information passed to the Reporter#jasmineDone event.

Properties:
Name Type Description
overallStatus OverallStatus

The overall result of the suite: 'passed', 'failed', or 'incomplete'.

totalTime Int

The total time (in ms) that it took to execute the suite

incompleteReason IncompleteReason

Explanation of why the suite was incomplete.

order Order

Information about the ordering (random or not) of this execution of the suite.

failedExpectations Array.<Expectation>

List of expectations that failed in an afterAll at the global level.

deprecationWarnings Array.<Expectation>

List of deprecation warnings that occurred at the global level.

Since:
  • 2.4.0

JasmineStartedInfo

Information passed to the Reporter#jasmineStarted event.

Properties:
Name Type Description
totalSpecsDefined Int

The total number of specs defined in this suite.

order Order

Information about the ordering (random or not) of this execution of the suite.

Since:
  • 2.0.0

SpecFilter(spec)

A function that takes a spec and returns true if it should be executed or false if it should be skipped.

Parameters:
Name Type Description
spec Spec

The spec that the filter is being applied to.

Returns:

boolean

SpecResult

Properties:
Name Type Description
id Int

The unique id of this spec.

description String

The description passed to the it that created this spec.

fullName String

The full description including all ancestors of this spec.

failedExpectations Array.<Expectation>

The list of expectations that failed during execution of this spec.

passedExpectations Array.<Expectation>

The list of expectations that passed during execution of this spec.

deprecationWarnings Array.<Expectation>

The list of deprecation warnings that occurred during execution this spec.

pendingReason String

If the spec is pending, this will be the reason.

status String

Once the spec has completed, this string represents the pass/fail status of this spec.

duration number

The time in ms used by the spec execution, including any before/afterEach.

properties Object

User-supplied properties, if any, that were set using Env#setSpecProperty

Since:
  • 2.0.0 x

SpecResult

Properties:
Name Type Description
id Int

The unique id of this spec.

description String

The description passed to the it that created this spec.

fullName String

The full description including all ancestors of this spec.

failedExpectations Array.<Expectation>

The list of expectations that failed during execution of this spec.

passedExpectations Array.<Expectation>

The list of expectations that passed during execution of this spec.

deprecationWarnings Array.<Expectation>

The list of deprecation warnings that occurred during execution this spec.

pendingReason String

If the spec is pending, this will be the reason.

status String

Once the spec has completed, this string represents the pass/fail status of this spec.

duration number

The time in ms used by the spec execution, including any before/afterEach.

properties Object

User-supplied properties, if any, that were set using Env#setSpecProperty

Since:
  • 2.0.0

SuiteResult

Properties:
Name Type Description
id Int

The unique id of this suite.

description String

The description text passed to the describe that made this suite.

fullName String

The full description including all ancestors of this suite.

failedExpectations Array.<Expectation>

The list of expectations that failed in an afterAll for this suite.

deprecationWarnings Array.<Expectation>

The list of deprecation warnings that occurred on this suite.

status String

Once the suite has completed, this string represents the pass/fail status of this suite.

duration number

The time in ms for Suite execution, including any before/afterAll, before/afterEach.

properties Object

User-supplied properties, if any, that were set using Env#setSuiteProperty

Since:
  • 2.0.0