Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • SinonSandbox

Index

Properties

assert

assert: SinonAssert

A convenience reference for sinon.assert Since sinon@2.0.0

clock

fake

fake: SinonFake

match

match: SinonMatch

mock

Works exactly like sinon.mock

requests

server

spy

Works exactly like sinon.spy

stub

Works exactly like sinon.stub.

Methods

createStubInstance

  • Creates a new object with the given functions as the prototype and stubs all implemented functions.

    remarks

    The given constructor function is not invoked. See also the stub API.

    Type parameters

    • TType

      Type being stubbed.

    Parameters

    • constructor: StubbableType<TType>

      Object or class to stub.

    • Optional overrides: {[ K in string | number | symbol]: SinonStubbedMember<TType[K]> | (TType[K] extends (...args: any[]) => R ? R : TType[K]) }

      An optional map overriding created stubs

    Returns SinonStubbedInstance<TType>

    A stubbed version of the constructor.

replace

  • replace<T, TKey>(obj: T, prop: TKey, replacement: T[TKey]): T[TKey]
  • Replaces property on object with replacement argument. Attempts to replace an already replaced value cause an exception. replacement can be any value, including spies, stubs and fakes. This method only works on non-accessor properties, for replacing accessors, use sandbox.replaceGetter() and sandbox.replaceSetter().

    Type parameters

    • T

    • TKey: string | number | symbol

    Parameters

    • obj: T
    • prop: TKey
    • replacement: T[TKey]

    Returns T[TKey]

replaceGetter

  • replaceGetter<T, TKey>(obj: T, prop: TKey, replacement: () => T[TKey]): () => T[TKey]
  • Replaces getter for property on object with replacement argument. Attempts to replace an already replaced getter cause an exception. replacement must be a Function, and can be instances of spies, stubs and fakes.

    Type parameters

    • T

    • TKey: string | number | symbol

    Parameters

    • obj: T
    • prop: TKey
    • replacement: () => T[TKey]
        • (): T[TKey]
        • Returns T[TKey]

    Returns () => T[TKey]

      • (): T[TKey]
      • Replaces getter for property on object with replacement argument. Attempts to replace an already replaced getter cause an exception. replacement must be a Function, and can be instances of spies, stubs and fakes.

        Returns T[TKey]

replaceSetter

  • replaceSetter<T, TKey>(obj: T, prop: TKey, replacement: (val: T[TKey]) => void): (val: T[TKey]) => void
  • Replaces setter for property on object with replacement argument. Attempts to replace an already replaced setter cause an exception. replacement must be a Function, and can be instances of spies, stubs and fakes.

    Type parameters

    • T

    • TKey: string | number | symbol

    Parameters

    • obj: T
    • prop: TKey
    • replacement: (val: T[TKey]) => void
        • (val: T[TKey]): void
        • Parameters

          • val: T[TKey]

          Returns void

    Returns (val: T[TKey]) => void

      • (val: T[TKey]): void
      • Replaces setter for property on object with replacement argument. Attempts to replace an already replaced setter cause an exception. replacement must be a Function, and can be instances of spies, stubs and fakes.

        Parameters

        • val: T[TKey]

        Returns void

reset

  • reset(): void
  • Resets the internal state of all fakes created through sandbox.

    Returns void

resetBehavior

  • resetBehavior(): void
  • Resets the behaviour of all stubs created through the sandbox. Since sinon@2.0.0

    Returns void

resetHistory

  • resetHistory(): void
  • Resets the history of all stubs created through the sandbox. Since sinon@2.0.0

    Returns void

restore

  • restore(): void
  • Restores all fakes created through sandbox.

    Returns void

useFakeServer

  • Fakes XHR and binds a server object to the sandbox such that it too is restored when calling sandbox.restore(). Access requests through sandbox.requests and server through sandbox.server

    Returns SinonFakeServer

useFakeTimers

    • No param : Causes Sinon to replace the global setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, process.hrtime, performance.now(when available) and Date with a custom implementation which is bound to the returned clock object. Starts the clock at the UNIX epoch (timestamp of 0).
    • Now : As above, but rather than starting the clock with a timestamp of 0, start at the provided timestamp now. Since sinon@2.0.0 You can also pass in a Date object, and its getTime() will be used for the starting timestamp.
    • Config : As above, but allows further configuration options, some of which are:
    • config.now - Number/Date - installs lolex with the specified unix epoch (default: 0)
    • config.toFake - String[ ] - an array with explicit function names to fake. By default lolex will automatically fake all methods except process.nextTick. You could, however, still fake nextTick by providing it explicitly
    • config.shouldAdvanceTime - Boolean - tells lolex to increment mocked time automatically based on the real system time shift (default: false)
    • Please visit the lolex.install documentation for the full feature set.
    • Important note: when faking nextTick, normal calls to process.nextTick() would not execute automatically as they would during normal event-loop phases. You would have to call either clock.next(), clock.tick(), clock.runAll() or clock.runToLast() (see example below). Please refer to the lolex documentation for more information.

    Parameters

    Returns SinonFakeTimers

useFakeXMLHttpRequest

  • Causes Sinon to replace the native XMLHttpRequest object in browsers that support it with a custom implementation which does not send actual requests. In browsers that support ActiveXObject, this constructor is replaced, and fake objects are returned for XMLHTTP progIds. Other progIds, such as XMLDOM are left untouched. The native XMLHttpRequest object will be available at sinon.xhr.XMLHttpRequest

    Returns SinonFakeXMLHttpRequestStatic

usingPromise

  • Causes all stubs created from the sandbox to return promises using a specific Promise library instead of the global one when using stub.rejects or stub.resolves. Returns the stub to allow chaining. Since sinon@2.0.0

    Parameters

    • promiseLibrary: any

    Returns SinonSandbox

verify

  • verify(): void
  • Verifies all mocks created through the sandbox.

    Returns void

verifyAndRestore

  • verifyAndRestore(): void
  • Verifies all mocks and restores all fakes created through the sandbox.

    Returns void