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-integration.mddocs/

Jest Integration

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

Capabilities

Jest Globals Setup

Main function that sets up Jest-specific globals including snapshots, expect matchers, and serializers.

/**
 * Sets up Jest globals and snapshot functionality
 * Configures snapshot state, serializers, and expect integration
 * @param options - Configuration options for Jest globals setup
 * @returns Promise resolving to configured SnapshotState
 */
function setupJestGlobals(options: SetupOptions): Promise<SnapshotState>;

/**
 * Configuration options for Jest globals setup
 */
interface SetupOptions {
  /** Jest project configuration */
  config: Config.ProjectConfig;
  /** Jest global configuration */
  globalConfig: Config.GlobalConfig;
  /** Local require function for loading modules */
  localRequire: (moduleName: string) => Plugin;
  /** Path to the test file being executed */
  testPath: string;
}

Snapshot State Management

Integration with Jest's snapshot testing system.

/**
 * Snapshot state management for test files
 * Handles snapshot creation, matching, and cleanup
 */
interface SnapshotState {
  /** Number of snapshots added during test run */
  added: number;
  /** Number of snapshots matched during test run */
  matched: number;
  /** Number of snapshots that didn't match */
  unmatched: number;
  /** Number of snapshots updated during test run */
  updated: number;
  
  /** Mark snapshots as checked for a specific test */
  markSnapshotsAsCheckedForTest(testName: string): void;
  
  /** Get count of unchecked snapshots */
  getUncheckedCount(): number;
  
  /** Get keys of unchecked snapshots */
  getUncheckedKeys(): Array<string>;
  
  /** Remove unchecked snapshot keys */
  removeUncheckedKeys(): void;
  
  /** Save snapshot state and return status */
  save(): { deleted: boolean };
}

Jest-Each Integration

Installs parameterized testing functionality using jest-each.

/**
 * Installs jest-each parameterized testing functionality
 * Adds .each method to test and describe functions
 * @param environment - Jest test environment to enhance
 */
function installEach(environment: JestEnvironment): void;

Error Handling Integration

Integration with Jest's error handling and private API protection.

/**
 * Installs error handling for deprecated/private Jasmine APIs
 * Throws errors when deprecated features are used if errorOnDeprecated is enabled
 * @param global - Global object to install error handling into
 */
function installErrorOnPrivate(global: Global.Global): void;

Expect Integration

Integration with Jest's expect assertion library.

/**
 * Jest expect integration setup
 * Configures expect matchers and assertion handling
 */
interface ExpectIntegration {
  /** Set up expect with configuration */
  setupExpect(options: { expand: boolean }): void;
  
  /** Extract expected assertion errors */
  extractExpectedAssertionsErrors(): Array<{
    actual: string;
    expected: string;
    error: Error;
  }>;
  
  /** Get suppressed errors from expect */
  getSuppressedErrors(): Array<Error>;
  
  /** Set expect state */
  setState(state: {
    currentTestName?: string;
    snapshotState?: SnapshotState;
    testPath?: string;
    suppressedErrors?: Array<Error>;
  }): void;
}

Integration Features

Parameterized Testing

Jest-each integration allows parameterized tests with table-driven data.

Usage Examples:

// Parameterized it tests
it.each([
  [1, 2, 3],
  [2, 3, 5],
  [3, 4, 7]
])("should add %i + %i = %i", (a, b, expected) => {
  expect(a + b).toBe(expected);
});

// Parameterized describe blocks
describe.each([
  ["positive", 1],
  ["negative", -1],
  ["zero", 0]
])("number behavior: %s", (description, value) => {
  it(`should handle ${description} numbers`, () => {
    expect(typeof value).toBe("number");
  });
});

// Object-based parameterization
it.each([
  { a: 1, b: 2, expected: 3 },
  { a: 2, b: 3, expected: 5 }
])("should add $a + $b = $expected", ({ a, b, expected }) => {
  expect(a + b).toBe(expected);
});

Concurrent Test Parameterization

Integration with concurrent testing for parameterized tests.

Usage Examples:

// Concurrent parameterized tests
it.concurrent.each([
  [1, 100],
  [2, 200], 
  [3, 300]
])("should process %i to get %i", async (input, expected) => {
  const result = await processAsync(input);
  expect(result).toBe(expected);
});

Snapshot Testing Integration

Automatic setup of snapshot testing capabilities.

Usage Examples:

// Snapshot testing works automatically
it("should match snapshot", () => {
  const data = { name: "test", value: 42 };
  expect(data).toMatchSnapshot();
});

// Inline snapshots
it("should match inline snapshot", () => {
  const result = formatData({ id: 1, name: "test" });
  expect(result).toMatchInlineSnapshot(`
    Object {
      "formatted": "test (1)",
    }
  `);
});

Custom Serializers

Support for custom snapshot serializers.

/**
 * Snapshot serializer plugin interface
 */
interface Plugin {
  /** Test if this serializer should handle the value */
  test(val: any): boolean;
  /** Serialize the value to a string */
  serialize(val: any, config: any, indentation: string, depth: number, refs: any): string;
}

Usage Examples:

// Custom serializer in Jest config
module.exports = {
  snapshotSerializers: [
    "my-custom-serializer",
    "<rootDir>/custom-serializer.js"
  ]
};

// Custom serializer implementation
module.exports = {
  test(val) {
    return val && val.constructor && val.constructor.name === "MyClass";
  },
  serialize(val) {
    return `MyClass { value: ${val.value} }`;
  }
};

Global Timeout Configuration

Integration with Jest's timeout configuration.

Usage Examples:

// Global timeout in Jest config
module.exports = {
  testTimeout: 10000, // 10 second default timeout
};

// Per-test timeout
it("should complete quickly", async () => {
  await fastOperation();
}, 1000); // 1 second timeout

// Jasmine-style timeout configuration
beforeEach(() => {
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000;
});

Mock Integration

Integration with Jest's mocking system for module and function mocks.

Usage Examples:

// Module mocking works automatically
jest.mock("./my-module");

// Function mocking  
const mockFn = jest.fn();
mockFn.mockReturnValue("mocked value");

// Spy integration with Jasmine spies
const spy = spyOn(obj, "method");
expect(spy).toHaveBeenCalled();

Setup Files Integration

Support for Jest's setup files configuration.

Usage Examples:

// Jest config with setup files
module.exports = {
  setupFilesAfterEnv: [
    "<rootDir>/setup-tests.js",
    "<rootDir>/custom-matchers.js"
  ]
};

// Setup file example (setup-tests.js)
import "jest-extended"; // Additional matchers

// Custom matcher
expect.extend({
  toBeWithinRange(received, floor, ceiling) {
    const pass = received >= floor && received <= ceiling;
    return {
      pass,
      message: () => 
        `expected ${received} to be within range ${floor} - ${ceiling}`
    };
  }
});

Environment Integration

Integration with different Jest test environments.

Usage Examples:

// Jest config with environment
module.exports = {
  testEnvironment: "jsdom", // or "node"
  testEnvironmentOptions: {
    url: "http://localhost"
  }
};

// Environment-specific globals are available
if (typeof window !== "undefined") {
  // Browser/jsdom environment
  expect(window.location.href).toBe("http://localhost/");
} else {
  // Node environment  
  expect(process.env.NODE_ENV).toBeDefined();
}

Configuration Integration

Jest-jasmine2 integrates with various Jest configuration options:

Project Configuration

  • snapshotSerializers: Custom snapshot serializers
  • setupFilesAfterEnv: Setup files to run after environment creation
  • testLocationInResults: Include test location information in results
  • fakeTimers: Fake timer configuration
  • resetModules/clearMocks/resetMocks/restoreMocks: Mock behavior settings

Global Configuration

  • expand: Expand diff output in assertion failures
  • updateSnapshot: Update snapshots during test run
  • testTimeout: Default timeout for all tests
  • maxConcurrency: Maximum concurrent tests for it.concurrent
  • errorOnDeprecated: Error on usage of deprecated APIs

Usage Examples:

// Complete Jest configuration for jest-jasmine2
module.exports = {
  testRunner: "jest-jasmine2",
  testEnvironment: "node",
  testTimeout: 10000,
  maxConcurrency: 4,
  setupFilesAfterEnv: ["<rootDir>/setup.js"],
  snapshotSerializers: ["my-serializer"],
  fakeTimers: {
    enableGlobally: true,
    legacyFakeTimers: false
  },
  clearMocks: true,
  resetMocks: false,
  restoreMocks: true
};

docs

async-support.md

index.md

jasmine-framework.md

jest-integration.md

reporting.md

test-runner.md

tile.json