CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-jasmine2

Jest test runner integration with Jasmine 2.x framework providing BDD-style testing capabilities

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Jest Jasmine2

Jest Jasmine2 is a Jest test runner adapter that integrates the Jasmine 2.x testing framework with Jest's testing environment. It provides a bridge between Jest's modern testing infrastructure and Jasmine's behavior-driven development (BDD) testing style, offering features like describe/it syntax, async test support, custom matchers, and test suite organization.

Package Information

  • Package Name: jest-jasmine2
  • Package Type: npm
  • Language: TypeScript
  • Installation: Part of Jest monorepo - typically installed via Jest

Core Imports

import jasmine2 from "jest-jasmine2";
import type { Jasmine, Reporter } from "jest-jasmine2";

For CommonJS:

const jasmine2 = require("jest-jasmine2").default;

Basic Usage

Jest Jasmine2 is primarily used internally by Jest as a test runner. It integrates with Jest's configuration and runtime systems:

import jasmine2 from "jest-jasmine2";
import type { Config } from "@jest/types";
import type { JestEnvironment } from "@jest/environment";
import type Runtime from "jest-runtime";

// Used within Jest's test execution pipeline
const result = await jasmine2(
  globalConfig,
  config,
  environment,
  runtime,
  testPath
);

Architecture

Jest Jasmine2 is built around several key components:

  • Main Test Runner: The jasmine2 function orchestrates test execution by integrating Jest configuration with Jasmine's test framework
  • Jasmine Integration: Custom Jasmine 2.x implementation with Jest-specific enhancements for async support, mocking, and snapshot testing
  • Reporter System: Converts Jasmine test results into Jest's TestResult format for consistent reporting
  • BDD Interface: Provides familiar describe/it syntax and lifecycle hooks (beforeEach, afterEach, etc.)
  • Async Support: Enhanced async/await and Promise support for modern JavaScript testing patterns
  • Global Extensions: Installs testing utilities like spies, matchers, and Jest-specific features into the global environment

Capabilities

Main Test Runner

The primary function that executes Jasmine tests within Jest's environment, handling configuration, setup, and result reporting.

function jasmine2(
  globalConfig: Config.GlobalConfig,
  config: Config.ProjectConfig,
  environment: JestEnvironment,
  runtime: Runtime,
  testPath: string,
): Promise<TestResult>;

Test Runner

Test Reporting

Jasmine to Jest test result reporting system that converts Jasmine's test results into Jest's standardized format.

class JasmineReporter implements Reporter {
  constructor(
    globalConfig: Config.GlobalConfig,
    config: Config.ProjectConfig,
    testPath: string,
  );
  
  getResults(): Promise<TestResult>;
  specDone(result: SpecResult): void;
  jasmineDone(runDetails: RunDetails): void;
}

interface Reporter {
  jasmineDone(runDetails: RunDetails): void;
  jasmineStarted(runDetails: RunDetails): void;
  specDone(result: SpecResult): void;
  specStarted(spec: SpecResult): void;
  suiteDone(result: SuiteResult): void;
  suiteStarted(result: SuiteResult): void;
}

Reporting

Jasmine Framework

Core Jasmine 2.x implementation with Jest-specific enhancements for test execution, spying, and BDD syntax.

interface Jasmine {
  _DEFAULT_TIMEOUT_INTERVAL: number;
  DEFAULT_TIMEOUT_INTERVAL: number;
  currentEnv_: ReturnType<typeof Env>['prototype'];
  getEnv(): ReturnType<typeof Env>['prototype'];
  createSpy: typeof createSpy;
  addMatchers(matchers: JasmineMatchersObject): void;
  version: string;
  testPath: string;
}

function create(createOptions: Record<string, any>): Jasmine;

function _interface(jasmine: Jasmine, env: any): {
  describe(description: string, specDefinitions: SpecDefinitionsFn): any;
  it(): any;
  beforeEach(): any;
  afterEach(): any;
  beforeAll(): any;
  afterAll(): any;
  spyOn(obj: Record<string, any>, methodName: string, accessType?: string): Spy;
  fail(): void;
  pending(): void;
}

Jasmine Framework

Async Testing Support

Enhanced async/await and Promise support for test functions and lifecycle hooks, with generator function support.

function jasmineAsyncInstall(
  globalConfig: Config.GlobalConfig,
  global: Global.Global,
): void;

Async Support

Jest Integration

Setup functions that integrate Jest-specific features like snapshots, expect matchers, and global utilities.

function setupJestGlobals(options: SetupOptions): Promise<SnapshotState>;

interface SetupOptions {
  config: Config.ProjectConfig;
  globalConfig: Config.GlobalConfig;
  localRequire: (moduleName: string) => Plugin;
  testPath: string;
}

function installEach(environment: JestEnvironment): void;

Jest Integration

Core Types

interface SpecDefinitionsFn {
  (): void;
}

interface AssertionErrorWithStack extends AssertionError {
  stack: string;
}

interface RunDetails {
  totalSpecsDefined?: number;
  failedExpectations?: SuiteResult['failedExpectations'];
}

interface Spy extends Record<string, any> {
  (this: Record<string, unknown>, ...args: Array<any>): unknown;
  and: SpyStrategy;
  calls: CallTracker;
  restoreObjectToOriginalState?: () => void;
}

interface JasmineMatchersObject {
  [id: string]: JasmineMatcher;
}

interface JasmineMatcher {
  (matchersUtil: unknown, context: unknown): JasmineMatcher;
  compare(...args: Array<unknown>): unknown;
  negativeCompare(...args: Array<unknown>): unknown;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/jest-jasmine2@30.1.x
Publish Source
CLI
Badge
tessl/npm-jest-jasmine2 badge