Jasmine CLI
The `jasmine` package provides a command-line interface (CLI) and supporting utilities for running Jasmine Behavior Driven Development (BDD) tests in Node.js environments. As of its current stable version 6.2.0, this package acts as a runner for `jasmine-core`, which is the actual testing framework. Jasmine is known for its clean and easy-to-understand syntax, requiring no DOM or external JavaScript frameworks, making it suitable for a wide range of JavaScript projects. The project maintains an active release cadence, with minor and patch updates frequently, and major versions introducing significant changes every few months. It is compatible with both ES modules and CommonJS modules and officially supports Node.js versions 20, 22, and 24, with best-effort support for environments past their end-of-life.
Common errors
-
ReferenceError: describe is not defined
cause This error occurs when a test file using Jasmine's global functions (`describe`, `it`, `expect`) is run directly with `node` instead of through the `jasmine` CLI or a configured test runner.fixRun your tests using `npx jasmine` (or `npm test` if configured) instead of `node your-spec-file.js`. Ensure Jasmine is correctly installed and initialized (`npx jasmine init`). -
TS2304: Cannot find name 'describe'
cause When using TypeScript, the global types for Jasmine's testing functions (`describe`, `it`, `expect`) are missing.fixInstall the Jasmine type definitions: `npm install --save-dev @types/jasmine`. Ensure your `tsconfig.json` includes `jasmine` in the `types` array or that `typeRoots` is correctly configured to find `@types` packages.
Warnings
- breaking Jasmine v6.0.0 dropped support for Node.js versions older than 20. Projects running on Node.js 18 or earlier will encounter issues.
- breaking The `ConsoleReporter` was moved from the `jasmine` package to `@jasminejs/reporters` in v6.0.0. Direct imports or references to `ConsoleReporter` from `jasmine` will break.
- breaking With Jasmine v6.0.0, if multiple configuration files are present, only the first one is loaded. This changes previous behavior where multiple configs might have been merged.
- breaking Jasmine-core v6.0.0 removed private APIs from its global namespace. Relying on undocumented or internal APIs will cause breakage, as these were never guaranteed to be stable.
- deprecated Jasmine v6.x emits deprecation warnings when used with `karma-jasmine` and other legacy Angular tools. Jasmine v7.0 will drop compatibility with these tools entirely.
- gotcha Jasmine only officially supports specific Node.js versions (20, 22, 24). Environments past end-of-life or odd-numbered Node versions are supported on a best-effort basis and may be dropped in future minor releases if support becomes impractical.
Install
-
npm install jasmine -
yarn add jasmine -
pnpm add jasmine
Imports
- Jasmine
const Jasmine = require('jasmine'); // For CommonJS in ESM context without appropriate configimport Jasmine from 'jasmine';
- describe, it, expect
/* No explicit import needed in spec files */
- Config
import type { Config } from 'jasmine';
Quickstart
/* src/greeter.ts */
export function greet(name: string): string {
return `Hello, ${name}!`;
}
/* spec/greeter.spec.ts */
import { greet } from '../src/greeter';
describe('Greeter', () => {
it('should return a greeting with the given name', () => {
expect(greet('World')).toEqual('Hello, World!');
});
it('should handle empty names gracefully', () => {
expect(greet('')).toEqual('Hello, !');
});
it('should support custom matchers if configured', () => {
// This test assumes a custom matcher 'toBeGreeting' is set up
// expect('Hello, Jasmine!').toBeGreeting();
expect(greet('Tester')).toContain('Tester');
});
});
/* Terminal commands */
// 1. Install Jasmine
npm install --save-dev jasmine
// 2. Initialize Jasmine project (creates spec/support/jasmine.json)
npx jasmine init
// 3. Run tests
npx jasmine