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 |
|
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 |
methodName |
String | The name of the method to replace with a |
- 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 |
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 |
||
propertyName |
String | The name of the property to replace with a |
||
accessType |
String |
<optional> |
get | The access type (get|set) of the property to |
- Since:
- 2.6.0
Returns:
- Type
- Spy
throwUnless(actual, actual) → {matchers}
Create an expectation for a spec and throw an error if it fails.
This is intended to allow Jasmine matchers to be used with tools like
testing-library's waitFor
, which expect matcher failures to throw
exceptions and not trigger a spec failure if the exception is caught.
It can also be used to integration-test custom matchers.
If the resulting expectation fails, a ThrowUnlessFailure
will be
thrown. A failed expectation will not result in a spec failure unless the
exception propagates back to Jasmine, either via the call stack or via
the global unhandled exception/unhandled promise rejection events.
Parameters:
Name | Type | Description |
---|---|---|
actual |
||
actual |
Object | Actual computed value to test expectations against. |
- Since:
- 5.1.0
Returns:
- Type
- matchers
throwUnlessAsync(actual, actual) → {matchers}
Create an asynchronous expectation for a spec and throw an error if it fails.
This is intended to allow Jasmine matchers to be used with tools like
testing-library's waitFor
, which expect matcher failures to throw
exceptions and not trigger a spec failure if the exception is caught.
It can also be used to integration-test custom matchers.
If the resulting expectation fails, a ThrowUnlessFailure
will be
thrown. A failed expectation will not result in a spec failure unless the
exception propagates back to Jasmine, either via the call stack or via
the global unhandled exception/unhandled promise rejection events.
Parameters:
Name | Type | Description |
---|---|---|
actual |
||
actual |
Object | Actual computed value to test expectations against. |
- Since:
- 5.1.0
Returns:
- Type
- matchers
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
DebugLogEntry
Properties:
Name | Type | Description |
---|---|---|
message |
String | The message that was passed to |
timestamp |
number | The time when the entry was added, in milliseconds from the spec's start time |
ExpectationResult
Describes the result of evaluating an expectation
Note: The expected and actual properties are deprecated and may be removed in a future release. In many Jasmine configurations they are passed through JSON serialization and deserialization, which is inherently lossy. In such cases, the expected and actual values may be placeholders or approximations of the original objects.
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 | Deprecated. If the expectation failed, what was the expected value. |
actual |
Object | Deprecated. If the expectation failed, what actual value was produced. |
globalErrorType |
String | undefined | The type of an error that is reported on the top suite. Valid values are undefined, "afterAll", "load", "lateExpectation", and "lateError". |
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 |
String | Human-readable explanation of why the suite was incomplete. |
incompleteCode |
String | Machine-readable explanation of why the suite was incomplete: 'focused', 'noSpecsFound', or undefined. |
order |
Order | Information about the ordering (random or not) of this execution of the suite. Note that this property is not present when Jasmine is run in parallel mode. |
numWorkers |
Int | Number of parallel workers. Note that this property is only present when Jasmine is run in parallel mode. |
failedExpectations |
Array.<ExpectationResult> | List of expectations that failed in an |
deprecationWarnings |
Array.<ExpectationResult> | 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. Note that this property is not present when Jasmine is run in parallel mode. |
order |
Order | Information about the ordering (random or not) of this execution of the suite. Note that this property is not present when Jasmine is run in parallel mode. |
parallel |
Boolean | Whether Jasmine is being run in parallel mode. |
- 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 |
String | The unique id of this spec. |
description |
String | The description passed to the |
fullName |
String | The full description including all ancestors of this spec. |
parentSuiteId |
String | null | The ID of the suite containing this spec, or null if this spec is not in a describe(). |
filename |
String | The name of the file the spec was defined in. |
failedExpectations |
Array.<ExpectationResult> | The list of expectations that failed during execution of this spec. |
passedExpectations |
Array.<ExpectationResult> | The list of expectations that passed during execution of this spec. |
deprecationWarnings |
Array.<ExpectationResult> | The list of deprecation warnings that occurred during execution this spec. |
pendingReason |
String | If the spec is |
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 |
debugLogs |
Array.<DebugLogEntry> | null | Messages, if any, that were logged using |
- Since:
- 2.0.0
SuiteResult
Properties:
Name | Type | Description |
---|---|---|
id |
String | The unique id of this suite. |
description |
String | The description text passed to the |
fullName |
String | The full description including all ancestors of this suite. |
parentSuiteId |
String | null | The ID of the suite containing this suite, or null if this is not in another describe(). |
filename |
String | The name of the file the suite was defined in. |
failedExpectations |
Array.<ExpectationResult> | The list of expectations that failed in an |
deprecationWarnings |
Array.<ExpectationResult> | 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 |
- Since:
- 2.0.0