@wpazderski/playwright-utils
    Preparing search index...

    Negated versions of asymmetric matchers e.g. expect.not.arrayContaining(...).

    expect

    interface ExpectNotAsymmetricMatchers {
        arrayContaining: (
            expected: unknown[],
        ) => ArrayContainingAsymmetricMatcher;
        closeTo: (expected: number, numDigits?: number) => CloseToAsymmetricMatcher;
        objectContaining: (
            expected: Record<string, unknown>,
        ) => ObjectContainingAsymmetricMatcher;
        stringContaining: (expected: string) => StringContainingAsymmetricMatcher;
        stringMatching: (
            expected: string | RegExp,
        ) => StringMatchingAsymmetricMatcher;
    }
    Index

    Properties

    arrayContaining: (expected: unknown[]) => ArrayContainingAsymmetricMatcher

    expect.arrayContaining() matches an array that contains all of the elements in the expected array, in any order. Note that received array may be a superset of the expected array and contain some extra elements.

    Use this method inside expect(value).toEqual(expected) to perform pattern matching.

    Usage

    expect([1, 2, 3]).toEqual(expect.arrayContaining([3, 1]));
    expect([1, 2, 3]).not.toEqual(expect.arrayContaining([1, 4]));

    Type declaration

      • (expected: unknown[]): ArrayContainingAsymmetricMatcher
      • expect.arrayContaining() matches an array that contains all of the elements in the expected array, in any order. Note that received array may be a superset of the expected array and contain some extra elements.

        Use this method inside expect(value).toEqual(expected) to perform pattern matching.

        Usage

        expect([1, 2, 3]).toEqual(expect.arrayContaining([3, 1]));
        expect([1, 2, 3]).not.toEqual(expect.arrayContaining([1, 4]));

        Parameters

        • expected: unknown[]

          Expected array that is a subset of the received value.

        Returns ArrayContainingAsymmetricMatcher

    Expected array that is a subset of the received value.

    closeTo: (expected: number, numDigits?: number) => CloseToAsymmetricMatcher

    Compares floating point numbers for approximate equality. Use this method inside expect(value).toEqual(expected) to perform pattern matching. When just comparing two numbers, prefer expect(value).toBeCloseTo(expected[, numDigits]).

    Usage

    expect({ prop: 0.1 + 0.2 }).not.toEqual({ prop: 0.3 });
    expect({ prop: 0.1 + 0.2 }).toEqual({ prop: expect.closeTo(0.3, 5) });

    Type declaration

    Expected value.

    The number of decimal digits after the decimal point that must be equal.

    objectContaining: (
        expected: Record<string, unknown>,
    ) => ObjectContainingAsymmetricMatcher

    expect.objectContaining() matches an object that contains and matches all of the properties in the expected object. Note that received object may be a superset of the expected object and contain some extra properties.

    Use this method inside expect(value).toEqual(expected) to perform pattern matching. Object properties can be matchers to further relax the expectation. See examples.

    Usage

    // Assert some of the properties.
    expect({ foo: 1, bar: 2 }).toEqual(expect.objectContaining({ foo: 1 }));

    // Matchers can be used on the properties as well.
    expect({ foo: 1, bar: 2 }).toEqual(expect.objectContaining({ bar: expect.any(Number) }));

    // Complex matching of sub-properties.
    expect({
    list: [1, 2, 3],
    obj: { prop: 'Hello world!', another: 'some other value' },
    extra: 'extra',
    }).toEqual(expect.objectContaining({
    list: expect.arrayContaining([2, 3]),
    obj: expect.objectContaining({ prop: expect.stringContaining('Hello') }),
    }));

    Type declaration

      • (expected: Record<string, unknown>): ObjectContainingAsymmetricMatcher
      • expect.objectContaining() matches an object that contains and matches all of the properties in the expected object. Note that received object may be a superset of the expected object and contain some extra properties.

        Use this method inside expect(value).toEqual(expected) to perform pattern matching. Object properties can be matchers to further relax the expectation. See examples.

        Usage

        // Assert some of the properties.
        expect({ foo: 1, bar: 2 }).toEqual(expect.objectContaining({ foo: 1 }));

        // Matchers can be used on the properties as well.
        expect({ foo: 1, bar: 2 }).toEqual(expect.objectContaining({ bar: expect.any(Number) }));

        // Complex matching of sub-properties.
        expect({
        list: [1, 2, 3],
        obj: { prop: 'Hello world!', another: 'some other value' },
        extra: 'extra',
        }).toEqual(expect.objectContaining({
        list: expect.arrayContaining([2, 3]),
        obj: expect.objectContaining({ prop: expect.stringContaining('Hello') }),
        }));

        Parameters

        • expected: Record<string, unknown>

          Expected object pattern that contains a subset of the properties.

        Returns ObjectContainingAsymmetricMatcher

    Expected object pattern that contains a subset of the properties.

    stringContaining: (expected: string) => StringContainingAsymmetricMatcher

    expect.stringContaining() matches a string that contains the expected substring. Use this method inside expect(value).toEqual(expected) to perform pattern matching.

    Usage

    expect('Hello world!').toEqual(expect.stringContaining('Hello'));
    

    Type declaration

    Expected substring.

    stringMatching: (expected: string | RegExp) => StringMatchingAsymmetricMatcher

    expect.stringMatching() matches a received string that in turn matches the expected pattern. Use this method inside expect(value).toEqual(expected) to perform pattern matching.

    Usage

    expect('123ms').toEqual(expect.stringMatching(/\d+m?s/));

    // Inside another matcher.
    expect({
    status: 'passed',
    time: '123ms',
    }).toEqual({
    status: expect.stringMatching(/passed|failed/),
    time: expect.stringMatching(/\d+m?s/),
    });

    Type declaration

      • (expected: string | RegExp): StringMatchingAsymmetricMatcher
      • expect.stringMatching() matches a received string that in turn matches the expected pattern. Use this method inside expect(value).toEqual(expected) to perform pattern matching.

        Usage

        expect('123ms').toEqual(expect.stringMatching(/\d+m?s/));

        // Inside another matcher.
        expect({
        status: 'passed',
        time: '123ms',
        }).toEqual({
        status: expect.stringMatching(/passed|failed/),
        time: expect.stringMatching(/\d+m?s/),
        });

        Parameters

        • expected: string | RegExp

          Pattern that expected string should match.

        Returns StringMatchingAsymmetricMatcher

    Pattern that expected string should match.