Comunica
    Preparing search index...

    Creates a test closure

    interface It {
        concurrent: It;
        each: Each;
        failing: It;
        only: It;
        skip: It;
        todo: (name: string) => void;
        (name: string, fn?: ProvidesCallback, timeout?: number): void;
    }
    • Creates a test closure.

      Parameters

      • name: string

        The name of your test

      • Optionalfn: ProvidesCallback

        The function for your test

      • Optionaltimeout: number

        The timeout for an async function test

      Returns void

    Index

    Properties

    concurrent: It

    Experimental and should be avoided.

    each: Each

    Use if you keep duplicating the same test with different data. .each allows you to write the test once and pass data in.

    .each is available with two APIs:

    • table: Array of Arrays with the arguments that are passed into the test fn for each row.
    • name: String the title of the test block.
    • fn: Function the test to be run, this is the function that will receive the parameters in each row as function arguments.
    • table: Tagged Template Literal
    • name: String the title of the test, use $variable to inject test data into the test title from the tagged template expressions.
    • fn: Function the test to be run, this is the function that will receive the test data object.
    // API 1
    test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
    '.add(%i, %i)',
    (a, b, expected) => {
    expect(a + b).toBe(expected);
    },
    );

    // API 2
    test.each`
    a | b | expected
    ${1} | ${1} | ${2}
    ${1} | ${2} | ${3}
    ${2} | ${1} | ${3}
    `('returns $expected when $a is added $b', ({a, b, expected}) => {
    expect(a + b).toBe(expected);
    });
    failing: It

    Mark this test as expecting to fail.

    Only available in the default jest-circus runner.

    only: It

    Only runs this test in the current file.

    skip: It

    Skips running this test in the current file.

    todo: (name: string) => void

    Sketch out which tests to write in the future.