Using Jasmine without global functions

Normally, Jasmine creates globals like describe, it, and expect that you can use to write your specs. If you’re running Jasmine 4.0 or later via Node.js you also have the option of importing the Jasmine interface rather than having Jasmine create globals.

Initialization when using the jasmine NPM package

Pass {globals: false} to the Jasmine constructor:

const Jasmine = require('jasmine');
const runner = new Jasmine({globals: false});

Or, if running in parallel:

const ParallelRunner = require('jasmine/parallel');
const runner = new ParallelRunner({
    numWorkers: 3,
    globals: false
});

Initialization when using jasmine-core directly

Initialize jasmine-core by calling noGlobals instead of boot:

const jasmine = require('jasmine-core').noGlobals().jasmine;

Writing spec and helper files

In each of your spec and helper files, use the jasmine-core module’s noGlobals function to obtain the things that would normally be provided as globals:

const {describe, beforeEach, it, expect, jasmine} = require('jasmine-core').noGlobals();

Then write your specs as usual.