Jasmine Spec Reporter

7.0.0 · maintenance · verified Sun Apr 19

jasmine-spec-reporter is a console reporter for the Jasmine behavior-driven development framework, providing real-time output of test results directly in the terminal. It is currently stable at version 7.0.0. The latest major release (v7.0.0) was published in April 2021, indicating a slower release cadence in recent years. The library is designed to offer a highly customizable and readable test reporting experience, especially beneficial in Node.js and Protractor test environments, and ships with comprehensive TypeScript type definitions. Key differentiators include extensive configuration options for output formatting, such as support for different stacktrace displays (none, raw, pretty) and customizable color themes for various test states. It offers a more detailed and configurable spec-by-spec breakdown compared to Jasmine's default reporter.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install and configure `jasmine-spec-reporter` with a minimal Jasmine test suite, showcasing basic options like stacktrace display and color settings.

import { SpecReporter, StacktraceOption } from 'jasmine-spec-reporter';
import * as Jasmine from 'jasmine'; // Ensure 'jasmine' package is installed

const runner = new Jasmine();

// Clear any default reporters to avoid duplicate output
runner.env.clearReporters();

// Add the SpecReporter with custom configuration
runner.env.addReporter(new SpecReporter({
  spec: {
    displayStacktrace: StacktraceOption.PRETTY, // Options: 'pretty', 'raw', 'none'
    displayDuration: true,
  },
  suite: {
    displayNumber: true,
  },
  summary: {
    displayPending: false,
    displayFailed: true,
    displayDuration: true,
  },
  colors: {
    success: 'green',
    failure: 'red',
    pending: 'yellow',
  },
  // For advanced customization, you can add custom processors:
  // customProcessors: [new MyCustomDisplayProcessor()],
}));

// Define a simple test suite for demonstration purposes
runner.describe('A basic test suite', () => {
  runner.it('should pass an assertion', () => {
    runner.expect(true).toBe(true);
  });

  runner.it('should fail an assertion', () => {
    runner.expect(1).toBe(2);
  });

  runner.pending('should be a pending test that is not run');
});

// Execute the tests (in a real scenario, this might be handled by a test runner)
runner.execute();

view raw JSON →