This class expresses the expectation about amount of invocations.

Example


const times = new Times(expected => expected === 1, `Should be called once`);
const actual = times.test(2);

expect(actual).toBe(false);
expect(times.message).toBe(`Should be called once`);

const mockName = 'mock name';
const mock = new Mock<ITestObject>(mockName);
const object = mock.object();

object.property;

const action = () => mock.verify(instance => instance.property, Times.AtLeast(2));

expect(action).toThrow();

Hierarchy

  • Times

Constructors

  • Parameters

    • evaluator: ((callCount) => boolean)

      It takes actual value and decides if it is expected or not. Returns true or false accordingly.

        • (callCount): boolean
        • Parameters

          • callCount: number

          Returns boolean

    • message: string

      A message that describes the expectation.

    Returns Times

Properties

message: string

A message that describes the expectation.

Methods

  • Evaluates the expectation against the actual value.

    Parameters

    • callCount: number

      The actual value.

    Returns boolean

  • It expects that the actual would be equal or bigger then the expected value.

    Parameters

    • callCount: number

      The expected value.

    Returns Times

  • It expects that the actual would be equal or smaller then the expected value.

    Parameters

    • callCount: number

      The expected value.

    Returns Times

  • It expects that the actual would be in the expected range of values.

    Parameters

    • callCountFrom: number

      The lowest bound of the range.

    • callCountTo: number

      The highest bound of the range.

    • range: Range

      Sets the rules where bounds of a range are included or excluded from the range.

    Returns Times

Generated using TypeDoc