Registry / testing / jasmine-core

jasmine-core

JSON →
library3.99.0jsnpmunverified

jasmine-core is the foundational, standalone JavaScript testing framework that underpins the broader Jasmine ecosystem. It provides the core APIs for writing specs (tests), matchers, and the test runner logic itself. While `jasmine-core` can be used directly for programmatic testing in both browser and Node.js environments, it's more commonly consumed as a dependency by higher-level packages like `jasmine` (for CLI execution) or `jasmine-browser-runner` for a more integrated experience. The current stable version is 6.2.0, with a major version 7.0.0-pre.0 already in pre-release. Jasmine maintains a regular release cadence, typically releasing minor and patch versions every 1-2 months, and major versions annually or bi-annually. Its key differentiators include its behavior-driven development (BDD) syntax, built-in assertion library, and lack of external dependencies for core functionality, making it a simple, self-contained solution for unit and integration testing.

npm install jasmine-core
INSTALL
IMPORT
SIG · JASMINE-CORE
J
jasmine-core
testingjavascriptv3.99.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jasmine
import { jasmine } from 'jasmine-core';
const jasmine = require('jasmine-core');
Primarily for programmatic setup. For ESM, direct import of `jasmine` as a named export is needed since v6. For CJS, `require('jasmine-core').getJasmineRequireObj()` is closer to the core object but still not directly `jasmine`.
bootJasmine
import { bootJasmine } from 'jasmine-core';
import bootJasmine from 'jasmine-core/lib/boot.js';
Used to initialize Jasmine globals for browser environments. Often implicitly called by `jasmine-browser-runner`.
getJasmineRequireObj
const { getJasmineRequireObj } = require('jasmine-core');
import { getJasmineRequireObj } from 'jasmine-core';
This is primarily a CommonJS export for internal use or advanced custom runners. Direct ESM import is generally not recommended as the primary interaction pattern for most users, and its usage differs from typical named exports.

This quickstart demonstrates how to programmatically configure and run Jasmine tests using the `Jasmine` class from the `jasmine` package (which wraps `jasmine-core`). It shows basic configuration loading and execution with a completion callback.

import Jasmine from 'jasmine'; const jasmine = new Jasmine(); // Configure Jasmine to use a custom reporter or default options jasmine.loadConfig({ spec_dir: 'spec', spec_files: [ '**/*[sS]pec.js' ], helpers: [ 'helpers/**/*.js' ], random: false, seed: null, stopSpecOnExpectationFailure: false, failFast: false }); // Add a simple spec file example (usually in a 'spec' directory) // This would typically be in a separate file, e.g., 'spec/my-spec.js' // describe('My Feature', () => { // it('should do something', () => { // expect(true).toBe(true); // }); // }); // For programmatic use, you can add a simple spec directly if not loading from files // For a more complete programmatic example, you'd typically load files. // Here's a placeholder for loading specs: // jasmine.addSpecFile('spec/my-spec.js'); jasmine.onComplete(function(passed) { if(passed) { console.log('All specs have passed'); } else { console.error('At least one spec has failed'); } }); jasmine.execute();
Debug
Known issues
breakingJasmine v6.0.0 dropped support for Node.js 14. Projects must now target Node.js 16 or newer. Node.js 18+ is required for the upcoming v7.0.0.
fix
Upgrade Node.js to v16 or higher for Jasmine v6.x, and v18 or higher for Jasmine v7.x.
affects: >=6.0.0
breakingWith Jasmine v6.0.0, the `default` export for `jasmine-core` was removed for ESM. You must now use named exports for ESM imports.
fix
Change `import Jasmine from 'jasmine-core';` to `import { Jasmine } from 'jasmine-core';` or `import * as Jasmine from 'jasmine-core';`.
affects: >=6.0.0
deprecated`jasmine.DEFAULT_TIMEOUT_INTERVAL` and `jasmine.getEnv()` are deprecated in v6.0.0. While they still work, direct access is discouraged.
fix
Use the configuration object passed to the `Jasmine` constructor or its methods to set timeout intervals and access environment specifics.
affects: >=6.0.0
breakingGlobal `expectAsync` is no longer available by default in Jasmine v6.0.0. It must be explicitly enabled if required.
fix
If `expectAsync` is critical, ensure your Jasmine configuration enables it or use `await expect()` for async matchers directly.
affects: >=6.0.0
breaking`jasmine.Spy` constructor was removed in v6.0.0. Spies should be created using `spyOn`, `createSpy`, or `createSpyObj`.
fix
Refactor code to use `spyOn(object, 'method')`, `jasmine.createSpy('mySpy')`, or `jasmine.createSpyObj('MyObj', ['method1', 'method2'])`.
affects: >=6.0.0
gotchaThe `jasmine.anything()` matcher now returns `true` for `null` and `undefined` in v6.0.0, which was not the case in previous versions.
fix
If strict non-null/non-undefined checks are needed, use `expect(value).not.toBeNull()` or `expect(value).not.toBeUndefined()` in addition to `jasmine.anything()` or create a custom matcher.
affects: >=6.0.0
Errors
Common errors & fixes
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jasmine-core' imported from ...
Attempting to `require('jasmine-core')` in an ESM context or `import` in CJS, or incorrect module resolution.
fix
Ensure your `package.json` `type` field is correctly set (e.g., `"type": "module"` for ESM files, or remove it for CJS). Use `import` statements for ESM and `require` for CJS. Verify the package is installed.
TypeError: jasmine.getEnv is not a function
Attempting to access `jasmine.getEnv()` directly after upgrading to Jasmine v6.x, where it's deprecated.
fix
Instead of `jasmine.getEnv()`, configure Jasmine via the `Jasmine` class instance (e.g., `new Jasmine().configure(...)`) or a configuration file. If migrating, consider using `jasmine-browser-runner` or the `jasmine` CLI package which abstract this.
TypeError: expectAsync is not a function
Attempting to use `expectAsync()` globally after upgrading to Jasmine v6.x without explicitly enabling it.
fix
Ensure your Jasmine configuration explicitly enables `expectAsync` if you need it as a global, or refactor to use `await expect()` for async matchers directly.
Upgrade
Version history
3.99.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources