Constructor
new Jasmine(options)
Parameters:
Name | Type | Description |
---|---|---|
options |
JasmineOptions | undefined |
Example
const Jasmine = require('jasmine');
const jasmine = new Jasmine();
Members
(readonly) env :Env
The Jasmine environment.
Type:
- Env
- See:
exitOnCompletion :boolean
Whether to cause the Node process to exit when the suite finishes executing.
Note: If onComplete
is called, Jasmine will not
exit when the suite completes even if exitOnCompletion is set to true.
Type:
- boolean
- Default Value:
- true
Methods
addHelperFile(filePath)
Adds a helper file to the list that will be loaded when the suite is executed.
Parameters:
Name | Type | Description |
---|---|---|
filePath |
string | The path to the file to be loaded. |
addHelperFiles()
Synonym for Jasmine#addMatchingHelperFiles
- Deprecated:
- Use
addMatchingHelperFiles
,loadConfig
, orloadConfigFile
instead.
- Use
addMatchers(matchers)
Add custom matchers for the current scope of specs.
Note: This is only callable from within a beforeEach
, it
, or beforeAll
.
Parameters:
Name | Type | Description |
---|---|---|
matchers |
Object | Keys from this object will be the new matcher names. |
- See:
addMatchingHelperFiles(patterns)
Adds files that match the specified patterns to the list of helper files.
Parameters:
Name | Type | Description |
---|---|---|
patterns |
Array.<string> | An array of helper file paths or globs that match helper files. Each path or glob will be evaluated relative to the spec directory. |
addMatchingSpecFiles(patterns)
Adds files that match the specified patterns to the list of spec files.
Parameters:
Name | Type | Description |
---|---|---|
patterns |
Array.<string> | An array of spec file paths or globs that match spec files. Each path or glob will be evaluated relative to the spec directory. |
addReporter(reporter)
Add a custom reporter to the Jasmine environment.
Parameters:
Name | Type | Description |
---|---|---|
reporter |
Reporter | The reporter to add |
- See:
addSpecFile(filePath)
Adds a spec file to the list that will be loaded when the suite is executed.
Parameters:
Name | Type | Description |
---|---|---|
filePath |
string | The path to the file to be loaded. |
addSpecFiles()
Synonym for Jasmine#addMatchingSpecFiles
- Deprecated:
- Use
addMatchingSpecFiles
,loadConfig
, orloadConfigFile
instead.
- Use
clearReporters()
Clears all registered reporters.
configureDefaultReporter(options)
Configures the default reporter that is installed if no other reporter is specified.
Parameters:
Name | Type | Description |
---|---|---|
options |
ConsoleReporterOptions |
coreVersion() → {string}
Returns:
The version of jasmine-core in use
- Type
- string
execute(filesopt, filterStringopt) → {Promise.<JasmineDoneInfo>}
Runs the test suite.
Note: Set exitOnCompletion
to false if you
intend to use the returned promise. Otherwise, the Node process will
ordinarily exit before the promise is settled.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
files |
Array.<string> |
<optional> |
Spec files to run instead of the previously configured set |
filterString |
string |
<optional> |
Regex used to filter specs. If specified, only specs with matching full names will be run. |
Returns:
Promise that is resolved when the suite completes.
- Type
- Promise.<JasmineDoneInfo>
loadConfig(config)
Loads configuration from the specified object.
Parameters:
Name | Type | Description |
---|---|---|
config |
Configuration |
loadConfigFile(configFilePathopt)
Loads configuration from the specified file. The file can be a JSON file or any JS file that's loadable via require and provides a Jasmine config as its default export.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
configFilePath |
string |
<optional> |
spec/support/jasmine.json |
onComplete(onCompleteCallback)
Registers a callback that will be called when execution finishes.
Note: Only one callback can be registered. The callback will be called after the suite has completed and the results have been finalized, but not necessarily before all of Jasmine's cleanup has finished. Calling this function will also prevent Jasmine from exiting the Node process at the end of suite execution.
Parameters:
Name | Type | Description |
---|---|---|
onCompleteCallback |
function |
- Deprecated:
- Set
exitOnCompletion
to false and use the promise returned fromexecute
instead.
- Set
provideFallbackReporter(reporter)
Provide a fallback reporter if no other reporters have been specified.
Parameters:
Name | Type | Description |
---|---|---|
reporter |
The fallback reporter |
- See:
randomizeTests(value)
Sets whether to randomize the order of specs.
Parameters:
Name | Type | Description |
---|---|---|
value |
boolean | Whether to randomize |
seed(seed)
Sets the random seed.
Parameters:
Name | Type | Description |
---|---|---|
seed |
number | The random seed |
showColors(value)
Sets whether to show colors in the console reporter.
Parameters:
Name | Type | Description |
---|---|---|
value |
boolean | Whether to show colors |
stopOnSpecFailure(value)
Sets whether to stop execution of the suite after the first spec failure.
Parameters:
Name | Type | Description |
---|---|---|
value |
boolean | Whether to stop execution of the suite after the first spec failure |
stopSpecOnExpectationFailure(value)
Sets whether to cause specs to only have one expectation failure.
Parameters:
Name | Type | Description |
---|---|---|
value |
boolean | Whether to cause specs to only have one expectation failure |