Jasmine JavaScript Testing Framework Documentation
repository·main·Indexed Apr 15, 2026
https://github.com/jasmine/jasmineJasmine is a Behavior Driven Development (BDD) testing framework for JavaScript that runs in Node.js and browsers without dependencies on the DOM or external frameworks. Supported environments include Node 20, 22, 24, and evergreen versions of Chrome, Firefox, Edge, and Safari. Key features include a natural language syntax, robust error handling, and a deprecation warning system. The framework provides jasmine.clock() for mocking timers (setTimeout, setInterval) and the Date object, allowing manual time advancement via tick() or auto-tick mode. It includes an ExceptionFormatter for readable stack traces and a Deprecator class to manage warnings about unsupported patterns like monkey-patching.
What's inside jasmine
Warning Context
mainDeprecation warnings include context about where they occurred:
- If the warning is at the top suite level, no context is added.
- If it's in a suite, the suite's full name is included.
- If it's in a spec, the spec's full name is included.
- A stack trace is included unless
omitStackTraceis set totrue.
Access Spec Metadata and Properties
mainYou can access metadata about the current spec via the
metadataproperty on the spec object. This provides read-only access to key identification and description details without exposing the full spec instance.Available metadata properties:
id: The unique ID of the spec (string).description: The description passed to theitblock that created this spec (string).getFullName(): Returns the full description including all ancestor suites (string).getPath(): Returns the full path of the spec as an array of names (available since v5.7.0).filename: The name of the file the spec was defined in (available since v5.13.0).
Note on
filename: The value may be incorrect ifzone.jsis installed or ifit/fit/xithave been replaced with versions that do not maintain the same call stack height. To fix this, set theextraItStackFramesconfiguration option.Usage:
// Inside a spec or reporter const specMetadata = this.metadata; console.log(specMetadata.id); console.log(specMetadata.getFullName()); console.log(specMetadata.getPath());Sources:
lib/jasmine-core/jasmine.jsUnderstand Suite metadata for reporting
mainThe
Suiteobject exposes ametadataproperty that provides read-only information about the test suite, useful for reporters or debugging.The
SuiteMetadataobject contains:id: The unique ID of the suite.parentSuite: The parent suite object (ornullif this is the top suite).description: The description passed to thedescribeblock.filename: The name of the file where the suite was defined. Note: This value may be incorrect ifzone.jsis installed or ifdescribe/fdescribe/xdescribehave been replaced with versions that don't maintain the same call stack height. You can fix this by settingConfiguration#extraItStackFrames.getFullName(): Returns the full description including all ancestors.children: An array of child specs or suites (returned as their metadata objects).
Example usage:
describe('My Suite', function() { it('has metadata', function() { const meta = this.currentSuite.metadata; console.log(meta.id, meta.description, meta.getFullName()); }); });Sources:
lib/jasmine-core/jasmine.jsUsage
mainUse
toBeRejectedwithexpectAsyncto check if a promise rejects:await expectAsync(aPromise).toBeRejected();Usage
mainit('matches all conditions', () => { const value = { name: 'Alice', age: 30 }; expect(value).toEqual(jasmine.allOf( jasmine.objectContaining({ name: 'Alice' }), jasmine.objectContaining({ age: jasmine.any(Number) }) )); });Use jasmine.empty to match empty collections
mainUse
jasmine.empty()to assert that a value is an empty collection (string, array, typed array, Map, Set, or object with no keys).Supported Types:
- Strings, Arrays, TypedArrays:
length === 0 - Maps, Sets:
size === 0 - Objects:
Object.keys(obj).length === 0
Usage:
expect([]).toEqual(jasmine.empty()); expect({}).toEqual(jasmine.empty()); expect(new Map()).toEqual(jasmine.empty()); expect('').toEqual(jasmine.empty());Note: This matcher returns
falsefor non-collection types (e.g., numbers, booleans, null).Sources:
lib/jasmine-core/jasmine.js- Strings, Arrays, TypedArrays:
Usage
mainUpgrading
mainIf you are upgrading from Jasmine 4.x, refer to the upgrading guide.
Sources:
README.mdUse jasmine.truthy to match truthy values
mainUse
jasmine.truthy()to assert that a value is truthy (evaluates totruein a boolean context).Truthy Values: Any value except
false,0,'',null,undefined,NaNUsage:
expect(1).toEqual(jasmine.truthy()); expect('hello').toEqual(jasmine.truthy()); expect({}).toEqual(jasmine.truthy());Note: This is the inverse of
jasmine.falsy().Sources:
lib/jasmine-core/jasmine.jsInstallation and Getting Started
mainUse toBeResolvedTo to assert resolved value equality
mainUse
toBeResolvedToto assert that a promise resolves to a specific value using deep equality comparison. This matcher checks both that the promise resolves and that the resolved value equals the expected value.Usage:
await expectAsync(aPromise).toBeResolvedTo({prop: 'value'}); return expectAsync(aPromise).toBeResolvedTo(42);If the promise rejects, the test fails with a message showing the rejection value. If the promise resolves to a different value, the test fails with a message showing both the expected and actual resolved values.
Sources:
lib/jasmine-core/jasmine.js