Go to repository

Interface ArrayExpectation<T>

This interface represents an expectation that is performed over an array.

interface ArrayExpectation<T> {
    not: ArrayExpectation<T>;
    allToSatisfy(criteria: ((item: T) => boolean)): ArrayExpectation<T> & FinishedExpectation;
    amountToSatisfy(count: number, criteria: ((item: T) => boolean)): ArrayExpectation<T> & FinishedExpectation;
    anyToSatisfy(criteria: ((item: T) => boolean)): ArrayExpectation<T> & FinishedExpectation;
    asArray<E>(): ArrayExpectation<E>;
    asNumber(): NumberExpectation;
    asObject<E>(): ObjectExpectation<E>;
    asString(): StringExpectation;
    toBe(value: T[]): ArrayExpectation<T> & FinishedExpectation;
    toBeDefined(): ArrayExpectation<T> & FinishedExpectation;
    toBeEmptyArray(): ArrayExpectation<T> & FinishedExpectation;
    toBeFalsy(): ArrayExpectation<T> & FinishedExpectation;
    toBeLike(value: T[]): ArrayExpectation<T> & FinishedExpectation;
    toBeNull(): ArrayExpectation<T> & FinishedExpectation;
    toBeTruthy(): ArrayExpectation<T> & FinishedExpectation;
    toBeUndefined(): ArrayExpectation<T> & FinishedExpectation;
    toContain(value: T): ArrayExpectation<T> & FinishedExpectation;
    toHaveAtPosition(value: T, position: number): ArrayExpectation<T> & FinishedExpectation;
    toHaveLength(count: number): ArrayExpectation<T> & FinishedExpectation;
    toHaveShape(shape: Shape): ArrayExpectation<T> & FinishedExpectation;
    toHaveType(value: string): ArrayExpectation<T> & FinishedExpectation;
}

Type Parameters

  • T

Hierarchy (view full)

Properties

This attribute retrieves an expectancy whose result value is false in case the matcher fulfills, and true otherwise.

Methods

Answer if all the element of the actual value satisfy a given criteria.

Parameters

  • criteria: ((item: T) => boolean)
      • (item): boolean
      • Parameters

        • item: T

        Returns boolean

Returns ArrayExpectation<T> & FinishedExpectation

Answer if a given amount of elements of the actual value satisfy a given criteria.

Parameters

  • count: number
  • criteria: ((item: T) => boolean)
      • (item): boolean
      • Parameters

        • item: T

        Returns boolean

Returns ArrayExpectation<T> & FinishedExpectation

Answer if any of the element of the actual value satisfy a given criteria.

Parameters

  • criteria: ((item: T) => boolean)
      • (item): boolean
      • Parameters

        • item: T

        Returns boolean

Returns ArrayExpectation<T> & FinishedExpectation

Answer the given expectation as an instance of IArrayExpectation. No check is performed on the input to see if it can actually be casted.

Type Parameters

  • E

Returns ArrayExpectation<E>

Answer the given expectation as an instance of INumberExpectation. No check is performed on the input to see if it can actually be casted.

Returns NumberExpectation

Answer the given expectation as an instance of IObjectExpectation. No check is performed on the input to see if it can actually be casted.

Type Parameters

  • E

Returns ObjectExpectation<E>

Answer the given expectation as an instance of IStringExpectation. No check is performed on the input to see if it can actually be casted.

Returns StringExpectation

Answers if the actual value is the same as expected, using strict compare. Do not use toBe with floating point numbers, use Expectations/Matchers.toBeCloseTo instead.

Parameters

  • value: T[]

Returns ArrayExpectation<T> & FinishedExpectation

Answers if the actual value is defined (as in not equal to undefined)

Returns ArrayExpectation<T> & FinishedExpectation

Answer if the actual value is empty.

Returns ArrayExpectation<T> & FinishedExpectation

Answers if the actual value is a falsy value.

Returns ArrayExpectation<T> & FinishedExpectation

Answers if the actual value is the same as expected, using a deep compare mechanism. Do not use toBeLike with floating point numbers, use Expectations/Matchers.toBeCloseTo instead.

Parameters

  • value: T[]

Returns ArrayExpectation<T> & FinishedExpectation

Answers if the actual value is null (strict null, not undefined).

Returns ArrayExpectation<T> & FinishedExpectation

Answers if the actual value is a truthy value.

Returns ArrayExpectation<T> & FinishedExpectation

Answers if the actual value is undefined.

Returns ArrayExpectation<T> & FinishedExpectation

Answer if the actual value contains the expected element.

Parameters

  • value: T

Returns ArrayExpectation<T> & FinishedExpectation

Answer if the actual value has a the expected element at a given position. Returns false if the position does not exist.

Parameters

  • value: T
  • position: number

Returns ArrayExpectation<T> & FinishedExpectation

Answer if the actual value has a length of expected number.

Parameters

  • count: number

Returns ArrayExpectation<T> & FinishedExpectation

Answer if the actual element has the given shape, as defined by the shapeOf submodule.

Parameters

  • shape: Shape

Returns ArrayExpectation<T> & FinishedExpectation

Answers if the actual value has a type matching the expected type, checked by using the typeof operator.

Parameters

  • value: string

Returns ArrayExpectation<T> & FinishedExpectation

`toHaveType('hello', 'string')` returns `true`.