Jasmine Core Testing Framework

6.2.0 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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();

view raw JSON →