CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jasmine-core

Simple JavaScript testing framework for browsers and node.js

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

test-organization.mddocs/

Test Organization

Core functions for defining test suites, individual tests, and setup/teardown hooks. Provides the fundamental structure for organizing and executing tests in Jasmine.

Capabilities

Suite Definition

Functions for creating test suites that group related specifications.

/**
 * Create a group/suite of specs
 * @param description - Descriptive name for the suite
 * @param specDefinitions - Function containing the specs and setup
 * @returns Suite object
 */
function describe(description: string, specDefinitions: () => void): Suite;

/**
 * Temporarily disable a suite (will be marked as pending)
 * @param description - Descriptive name for the suite
 * @param specDefinitions - Function containing the specs and setup
 * @returns Suite object
 */
function xdescribe(description: string, specDefinitions: () => void): Suite;

/**
 * Focus on this suite (only focused suites and specs will run)
 * @param description - Descriptive name for the suite
 * @param specDefinitions - Function containing the specs and setup
 * @returns Suite object
 */
function fdescribe(description: string, specDefinitions: () => void): Suite;

Usage Examples:

describe('User Authentication', () => {
  describe('when user is logged in', () => {
    it('should show dashboard', () => {
      // test implementation
    });
  });

  describe('when user is not logged in', () => {
    it('should redirect to login page', () => {
      // test implementation
    });
  });
});

// Temporarily skip a suite
xdescribe('Feature in development', () => {
  it('will not run', () => {
    // this won't execute
  });
});

// Focus on specific suite during development
fdescribe('Current feature being tested', () => {
  it('only this suite will run', () => {
    // only focused suites/specs execute
  });
});

Spec Definition

Functions for defining individual test specifications.

/**
 * Define a single test/specification
 * @param description - Descriptive name for the test
 * @param testFunction - Optional function containing test logic
 * @param timeout - Optional timeout in milliseconds
 * @returns Spec object
 */
function it(description: string, testFunction?: () => void | Promise<void>, timeout?: number): Spec;

/**
 * Temporarily disable a spec (will be marked as pending)
 * @param description - Descriptive name for the test
 * @param testFunction - Optional function containing test logic
 * @returns Spec object
 */
function xit(description: string, testFunction?: () => void | Promise<void>): Spec;

/**
 * Focus on this spec (only focused suites and specs will run)
 * @param description - Descriptive name for the test
 * @param testFunction - Optional function containing test logic
 * @param timeout - Optional timeout in milliseconds
 * @returns Spec object
 */
function fit(description: string, testFunction?: () => void | Promise<void>, timeout?: number): Spec;

Usage Examples:

describe('Calculator', () => {
  it('should add two numbers', () => {
    const result = add(2, 3);
    expect(result).toEqual(5);
  });

  // Asynchronous test
  it('should fetch user data', async () => {
    const user = await fetchUser(123);
    expect(user.name).toBe('John');
  });

  // Test with custom timeout
  it('should handle slow operations', () => {
    // test logic
  }, 10000); // 10 second timeout

  // Pending test (no implementation yet)
  it('should handle edge case');

  // Temporarily disabled test
  xit('should work with legacy API', () => {
    // this won't run
  });

  // Focused test for development
  fit('should validate new feature', () => {
    // only this test will run
  });
});

Setup and Teardown Hooks

Functions for running setup and cleanup code before and after tests.

/**
 * Run before each spec in the describe block
 * @param action - Function to execute before each spec
 * @param timeout - Optional timeout in milliseconds
 */
function beforeEach(action: () => void | Promise<void>, timeout?: number): void;

/**
 * Run after each spec in the describe block
 * @param action - Function to execute after each spec
 * @param timeout - Optional timeout in milliseconds
 */
function afterEach(action: () => void | Promise<void>, timeout?: number): void;

/**
 * Run once before all specs in the describe block
 * @param action - Function to execute before all specs
 * @param timeout - Optional timeout in milliseconds
 */
function beforeAll(action: () => void | Promise<void>, timeout?: number): void;

/**
 * Run once after all specs in the describe block
 * @param action - Function to execute after all specs
 * @param timeout - Optional timeout in milliseconds
 */
function afterAll(action: () => void | Promise<void>, timeout?: number): void;

Usage Examples:

describe('Database operations', () => {
  let database;

  beforeAll(async () => {
    // Setup shared resources once
    database = await connectToDatabase();
  });

  afterAll(async () => {
    // Cleanup shared resources
    await database.close();
  });

  beforeEach(() => {
    // Reset state before each test
    database.clearCache();
  });

  afterEach(() => {
    // Cleanup after each test
    database.rollbackTransaction();
  });

  it('should save user', async () => {
    const user = await database.save({ name: 'Alice' });
    expect(user.id).toBeDefined();
  });

  it('should find user', async () => {
    await database.save({ name: 'Bob' });
    const user = await database.findByName('Bob');
    expect(user).toBeDefined();
  });
});

Spec Control Functions

Functions for controlling spec execution and marking specs as pending or failed.

/**
 * Mark the current spec as pending with an optional message
 * @param message - Optional reason for pending status
 */
function pending(message?: string): void;

/**
 * Explicitly fail the current spec with an error message
 * @param error - Error message or Error object
 */
function fail(error?: string | Error): void;

Usage Examples:

describe('Feature tests', () => {
  it('should implement complex feature', () => {
    if (!featureImplemented) {
      pending('Feature not yet implemented');
      return;
    }
    
    // test implementation
  });

  it('should validate input', () => {
    const input = getInput();
    
    if (!input) {
      fail('No input provided for test');
    }
    
    expect(validateInput(input)).toBe(true);
  });
});

Spec and Suite Properties

Functions for adding custom properties to test results.

/**
 * Set a user-defined property on the current spec result
 * @param key - Property name
 * @param value - Property value
 */
function setSpecProperty(key: string, value: any): void;

/**
 * Set a user-defined property on the current suite result
 * @param key - Property name
 * @param value - Property value
 */
function setSuiteProperty(key: string, value: any): void;

Usage Examples:

describe('Performance tests', () => {
  it('should complete within time limit', () => {
    const startTime = Date.now();
    
    performOperation();
    
    const duration = Date.now() - startTime;
    setSpecProperty('executionTime', duration);
    setSpecProperty('category', 'performance');
    
    expect(duration).toBeLessThan(1000);
  });
});

describe('API tests', () => {
  beforeAll(() => {
    setSuiteProperty('testEnvironment', 'staging');
    setSuiteProperty('apiVersion', '2.1');
  });

  it('should return user data', () => {
    // test implementation
  });
});

Types

interface Suite {
  id: number;
  description: string;
  fullName: string;
  parentSuite?: Suite;
  children: (Suite | Spec)[];
  status?: 'disabled' | 'pending' | 'finished';
}

interface Spec {
  id: number;
  description: string;
  fullName: string;
  suite: Suite;
  result: SpecResult;
  status?: 'disabled' | 'pending' | 'started' | 'finished';
}

interface SpecResult {
  id: number;
  description: string;
  fullName: string;
  status: 'passed' | 'failed' | 'pending';
  pendingReason?: string;
  failedExpectations: ExpectationResult[];
  passedExpectations: ExpectationResult[];
  deprecationWarnings: ExpectationResult[];
  properties?: { [key: string]: any };
}

docs

custom-extensions.md

environment-config.md

expectations-matchers.md

index.md

spy-system.md

test-organization.md

test-utilities.md

tile.json