Interface IPresetBuilder<T, TValue>

Sets a behaviour rule for a particular use case

Type Parameters

  • T

    The type of mocked object.

  • TValue = any

Hierarchy

  • IPresetBuilder

Methods

  • Example


    const ipcRendererMock = new StrictMock<typeof ipcRenderer>()
    .setup(instance => instance.on(ipcRendererChannelName, It.IsAny()))
    .callback(({args: [channel, listener]}) => listener(undefined, response));

    Parameters

    • callback: ((interaction) => TValue)

      A callback function that will intercept the interaction. The function may returns a value that will be provided as result (see returns)

        • (interaction): TValue
        • Parameters

          Returns TValue

    Returns IMock<T>

  • Replicates interactions with original object. The mock object keeps tracking all interactions and reflects them on the original object.

    Example


    const value = 2;

    class Origin {
    public property = value;
    }

    const origin = new Origin();
    const mock = new Mock<Origin>()
    .setup(() => It.IsAny())
    .mimics(origin);

    const actual = mock.object().property;
    expect(actual).toBe(2);

    Parameters

    • origin: T

    Returns IMock<T>

  • Returns the provided value as a result of interaction in case of

    • get property value
    • invocation a function

    Controls write operation in case of

    • property assignment (true - the assignment is allowed, false - the assignment is not allowed)

    Parameters

    • value: TValue

      The value

    Returns IMock<T>

  • Returns the provided value with a rejected Promise as a result of interaction with an asynchronous function.

    Type Parameters

    • TException

    Parameters

    • exception: TException

    Returns IMock<T>

Generated using TypeDoc