Upgrading to Jasmine 7.0
Contents
If you use Karma or Zone.js
The current version of karma-jasmine is incompatible with jasmine-core 7.x. Karma-jasmine was deprecated in 2022 and has not been updated since then. If you use Karma, consider switching to a maintained alternative such as jasmine-browser-runner or web-test-runner-jasmine.
Zone.js relies on monkey patching jasmine-core. That no longer works in 7.0. If you use Zone.js, you won’t be able to upgrade to jasmine-core 7.0 or later.
Preparation
Before installing 7.x, upgrade to the latest jasmine-core 6.x and, if applicable, the latest jasmine 6.x, if applicable. Then fix any deprecation warnings that you see when you run your specs.
Upgrading jasmine-core
If you’re using the jasmine package, upgrade to version 7.0.0 or later. This will also cause jasmine-core to be upgraded. If you’re using jasmine-browser-runner, upgrade to version 5.0.0 or later. Your package manager (npm/yarn/etc) should automatically install jasmine-core 7.0.0 or later unless your package.json file specifies an earlier version.
Updating your code for 7.0
Node boot changes
The node.js boot APIs exposed by jasmine-core have changed. If you call them
directly rather than using the jasmine package, you’ll need to update your code.
In 6.x, the boot function took a parameter indicating whether to reinitialize
jasmine-core or return an existing instance, and created globals such as it
and expect. There was a separate noGlobals function that booted without
creating globals. In 7.0, boot and noGlobals no longer exist. Instead,
jasmine-core boots itself but does not automatically install globals. It exports
an installGlobals function that installs the globals that were previously
installed by boot, and a reset function to discard all state and
configuration and reinitialize.
| Scenario | 6.x | 7.0 |
|---|---|---|
| Typical usage with globals |
|
|
| No globals |
|
|
| Discard existing state |
|
|
Browser boot changes
The browser boot process has been simplified. If you use jasmine-browser-runner,
you don’t need to make any changes. If you maintain your own boot files, you
should update them to match
the boot.js file distributed with jasmine-core.
If you need to call jasmine.getEnv().configure(), you can do that any time
after jasmine.js loads and before env.execute() is called.
Node configuration changes
jsLoader: "require"
The jsLoader configuration setting is no longer supported. You may be able to
just remove it, since the default loader now handles most of the original uses
for jsLoader: "require". If that doesn’t work, you can provide a custom
loader that implements any module
loading strategy you need.
Default reporter configuration
| Scenario | 6.x | 7.0 |
|---|---|---|
| Configuring default reporter via config file (jasmine.mjs, jasmine.json, etc) |
|
|
Configuring default reporter via the Jasmine or
ParallelRunner classes
|
|
|
Reporters
Jasmine-core 7.0.0 adds a new spec status 'notApplicable', which is similar to
'pending' but has a more specific meaning. It means that the spec was skipped
because it doesn’t apply to the current environment. It’s emitted when the spec
calls notApplicable. If you have a
reporter that deals with spec statuses, update it to handle'notApplicable'.
Jasmine-browser-runner middleware
Jasmine-browser-runner no longer depends on Express. That won’t affect most
users, but it’s a breaking change if you use custom middleware. Middleware are
now functions that take request, response, and next parameters. For
example:
// jasmine-browser.mjs
module.exports = {
// ...
"middleware": {
"/": function(req, res, next) {
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
next();
}
}
};