Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface SpyBehavior

Provides options for controlling how a Spy behaves when invoked.

see

Spy

Hierarchy

Index

Methods

  • invokes(fn: Function): Spy
  • Calls the specified method when the Spy is invoked.

    example
    import { spy } from '@paychex/core';

    const method = spy().invokes(function(...args) {
    console.log('method called with', args);
    });

    method.onCall(1).invokes(function(...args) {
    console.log('method called 2nd time', args);
    });

    Parameters

    • fn: Function

    Returns Spy

    The original context, for chaining.

  • returns(value: any): Spy
  • Returns the specified value when the Spy is invoked.

    example
    import { spy } from '@paychex/core';

    const method = spy().returns('abc');

    method.onCall(1).returns('def');

    Parameters

    • value: any

      The value to return.

    Returns Spy

    The original context, for chaining.

  • throws(err: Error): Spy
  • Throws the specified value when the Spy is invoked.

    example
    import { spy } from '@paychex/core';

    const method = spy().throws(new Error());

    method.onCall(1).throws(new Error('2nd call'));

    Parameters

    • err: Error

    Returns Spy

    The original context, for chaining.