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

jasmine-framework.mddocs/

Jasmine Framework

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

Capabilities

Jasmine Instance Creation

Factory function that creates a configured Jasmine instance with Jest-specific enhancements.

/**
 * Creates a new Jasmine instance with Jest-specific configuration
 * @param createOptions - Configuration options for the Jasmine instance
 * @returns Configured Jasmine instance
 */
function create(createOptions: Record<string, any>): Jasmine;

Jasmine Interface

The main Jasmine interface providing access to core functionality and configuration.

/**
 * Main Jasmine interface with Jest-specific enhancements
 */
interface Jasmine {
  /** Internal default timeout interval */
  _DEFAULT_TIMEOUT_INTERVAL: number;
  /** Default timeout interval for tests (configurable) */
  DEFAULT_TIMEOUT_INTERVAL: number;
  /** Current test environment instance */
  currentEnv_: ReturnType<typeof Env>['prototype'];
  /** Test path being executed */
  testPath: string;
  /** Jasmine version string */
  version: string;
  
  /** Get the current test environment */
  getEnv(): ReturnType<typeof Env>['prototype'];
  /** Create a spy function */
  createSpy: typeof createSpy;
  /** Add custom matchers to the test environment */
  addMatchers(matchers: JasmineMatchersObject): void;
  
  // Jasmine class constructors
  Env: ReturnType<typeof Env>;
  JsApiReporter: typeof JsApiReporter;
  ReportDispatcher: typeof ReportDispatcher;
  Spec: typeof Spec;
  SpyRegistry: typeof SpyRegistry;
  Suite: typeof Suite;
  Timer: typeof Timer;
}

BDD Interface Creation

Creates the BDD interface that provides describe, it, and other testing functions.

/**
 * Creates the BDD interface for test writing
 * @param jasmine - The Jasmine instance
 * @param env - The test environment
 * @returns Object containing BDD functions
 */
function _interface(jasmine: Jasmine, env: any): BDDInterface;

interface BDDInterface {
  /** Define a test suite */
  describe(description: string, specDefinitions: SpecDefinitionsFn): Suite;
  /** Define a disabled/skipped test suite */
  xdescribe(description: string, specDefinitions: SpecDefinitionsFn): Suite;
  /** Define a focused test suite (only this suite runs) */
  fdescribe(description: string, specDefinitions: SpecDefinitionsFn): Suite;
  
  /** Define a test specification */
  it(description: string, testFn?: TestFn, timeout?: number): Spec;
  /** Define a disabled/skipped test */
  xit(description: string, testFn?: TestFn, timeout?: number): Spec;
  /** Define a focused test (only this test runs) */
  fit(description: string, testFn?: TestFn, timeout?: number): Spec;
  
  /** Setup function to run before each test */
  beforeEach(setupFn: SetupFn, timeout?: number): void;
  /** Teardown function to run after each test */
  afterEach(teardownFn: TeardownFn, timeout?: number): void;
  /** Setup function to run before all tests in suite */
  beforeAll(setupFn: SetupFn, timeout?: number): void;
  /** Teardown function to run after all tests in suite */
  afterAll(teardownFn: TeardownFn, timeout?: number): void;
  
  /** Mark a test as pending */
  pending(): void;
  /** Explicitly fail a test */
  fail(message?: string): void;
  
  /** Create a spy on an object method */
  spyOn(obj: Record<string, any>, methodName: string, accessType?: string): Spy;
  
  /** Jasmine API reporter instance */
  jsApiReporter: JsApiReporter;
  /** Reference to the Jasmine instance */
  jasmine: Jasmine;
}

Test Environment

The Jasmine test environment that manages test execution and state.

/**
 * Jasmine test environment managing test execution
 */
interface JasmineEnv {
  /** Execute all registered tests */
  execute(): Promise<void>;
  
  /** Add a reporter to receive test events */
  addReporter(reporter: Reporter): void;
  
  /** Filter function for specs */
  specFilter?: (spec: Spec) => boolean;
  
  /** Register a test suite */
  describe(description: string, specDefinitions: SpecDefinitionsFn): Suite;
  
  /** Register a test specification */
  it(description: string, testFn?: TestFn, timeout?: number): Spec;
  
  /** Setup/teardown hooks */
  beforeEach(setupFn: SetupFn, timeout?: number): void;
  afterEach(teardownFn: TeardownFn, timeout?: number): void;
  beforeAll(setupFn: SetupFn, timeout?: number): void;
  afterAll(teardownFn: TeardownFn, timeout?: number): void;
  
  /** Test control functions */
  pending(): void;
  fail(message?: string): void;
  
  /** Spy creation */
  spyOn(obj: Record<string, any>, methodName: string, accessType?: string): Spy;
  
  /** Todo test marker */
  todo(description: string): Spec;
}

Spy System

Jasmine's spy functionality for mocking and tracking function calls.

/**
 * Creates a spy function for testing
 * @param name - Optional name for the spy
 * @param originalFn - Optional original function to spy on
 * @returns Spy function with tracking capabilities
 */
function createSpy(name?: string, originalFn?: Function): Spy;

/**
 * Spy object with call tracking and behavior modification
 */
interface Spy extends Record<string, any> {
  /** The spy function itself */
  (this: Record<string, unknown>, ...args: Array<any>): unknown;
  
  /** Spy behavior configuration */
  and: SpyStrategy;
  
  /** Call tracking information */
  calls: CallTracker;
  
  /** Restore original object state (for spyOn) */
  restoreObjectToOriginalState?: () => void;
}

/**
 * Spy behavior strategy for configuring return values and call behavior
 */
interface SpyStrategy {
  /** Return a specific value */
  returnValue(value: any): Spy;
  
  /** Return different values in sequence */
  returnValues(...values: any[]): Spy;
  
  /** Call the original function */
  callThrough(): Spy;
  
  /** Call a fake function instead */
  callFake(fn: Function): Spy;
  
  /** Throw an error when called */
  throwError(errorMsg?: string | Error): Spy;
  
  /** Reset the spy to default behavior */
  stub(): Spy;
}

/**
 * Call tracking for spy functions
 */
interface CallTracker {
  /** Whether the spy has been called */
  any(): boolean;
  
  /** Number of times the spy was called */
  count(): number;
  
  /** Arguments from a specific call */
  argsFor(index: number): any[];
  
  /** All calls made to the spy */
  allArgs(): any[][];
  
  /** All calls with context information */
  all(): Array<{
    object: any;
    args: any[];
    returnValue: any;
  }>;
  
  /** Most recent call */
  mostRecent(): {
    object: any;
    args: any[];
    returnValue: any;
  };
  
  /** First call made */
  first(): {
    object: any;
    args: any[];
    returnValue: any;
  };
  
  /** Reset call tracking */
  reset(): void;
}

Custom Matchers

System for adding custom assertion matchers to Jasmine.

/**
 * Collection of custom matchers
 */
interface JasmineMatchersObject {
  [matcherName: string]: JasmineMatcher;
}

/**
 * Individual matcher function
 */
interface JasmineMatcher {
  /** Matcher factory function */
  (matchersUtil: MatchersUtil, context: MatcherContext): {
    compare(actual: any, ...expected: any[]): MatcherResult;
    negativeCompare?(actual: any, ...expected: any[]): MatcherResult;
  };
}

interface MatcherResult {
  pass: boolean;
  message: string | (() => string);
}

interface MatchersUtil {
  equals(a: any, b: any): boolean;
  contains(haystack: any, needle: any): boolean;
  buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: any[]): string;
}

interface MatcherContext {
  isNot?: boolean;
  actual?: any;
}

Usage Examples:

import { create, _interface } from "jest-jasmine2/build/jasmine/jasmineLight";

// Create Jasmine instance
const jasmine = create({
  testTimeout: 5000,
  testPath: "/path/to/test.js"
});

// Get test environment
const env = jasmine.getEnv();

// Create BDD interface
const bddInterface = _interface(jasmine, env);

// Use BDD functions
bddInterface.describe("Test Suite", () => {
  bddInterface.it("should work", () => {
    expect(true).toBe(true);
  });
});

// Create spies
const spy = jasmine.createSpy("testSpy");
spy.and.returnValue("mocked value");

const objectSpy = bddInterface.spyOn(obj, "method");
expect(objectSpy).toHaveBeenCalled();

docs

async-support.md

index.md

jasmine-framework.md

jest-integration.md

reporting.md

test-runner.md

tile.json