@types/sinon

  • Version 21.0.0
  • Published
  • 65.3 kB
  • 1 dependency
  • MIT license

Install

npm i @types/sinon
yarn add @types/sinon
pnpm add @types/sinon

Overview

TypeScript definitions for sinon

Index

Variables

Interfaces

Type Aliases

Variables

variable Sinon

const Sinon: Sinon.SinonStatic;

    Interfaces

    interface SandboxReplace

    interface SandboxReplace {}

      method usingAccessor

      usingAccessor: <T, TKey extends keyof T, R extends T[TKey] = T[TKey]>(
      obj: T,
      prop: TKey,
      replacement: R
      ) => R;
      • Assigns a value to a property on object with replacement argument. replacement can be any value, including spies, stubs and fakes. This method only works on accessor properties.

      call signature

      <T, TKey extends keyof T, R extends T[TKey] = T[TKey]>(
      obj: T,
      prop: TKey,
      replacement: R
      ): R;
      • 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().

      interface SimplifiedMap

      interface SimplifiedMap extends SimplifiedSet {}

        method get

        get: (key: any) => any;

          interface SimplifiedSet

          interface SimplifiedSet {}

            method has

            has: (el: any) => boolean;

              interface SinonApi

              interface SinonApi {}

                property addBehavior

                addBehavior: (
                name: string,
                fn: (fake: SinonStub, ...userArgs: any[]) => void
                ) => void;
                • Add a custom behavior. The name will be available as a function on stubs, and the chaining mechanism will be set up for you (e.g. no need to return anything from your function, its return value will be ignored). The fn will be passed the fake instance as its first argument, and then the user's arguments.

                property clock

                clock: {
                create(now: number | Date): FakeTimers.Clock;
                };

                  property defaultConfig

                  defaultConfig: Partial<SinonSandboxConfig>;

                    property expectation

                    expectation: SinonExpectationStatic;

                      property setFormatter

                      setFormatter: (customFormatter: (...args: any[]) => string) => void;
                      • Replace the default formatter used when formatting ECMAScript object An example converts a basic object, such as {id: 42 }, to a string on a format of your choosing, such as "{ id: 42 }"

                      method createSandbox

                      createSandbox: (config?: Partial<SinonSandboxConfig>) => SinonSandbox;
                      • Creates a new sandbox object with spies, stubs, and mocks.

                        Parameter config

                      method promise

                      promise: <T = unknown>(
                      executor?: (
                      resolve: (value: T) => void,
                      reject: (reason?: unknown) => void
                      ) => void
                      ) => SinonPromise<T>;

                        interface SinonArrayMatcher

                        interface SinonArrayMatcher extends SinonMatcher {}

                          method contains

                          contains: (expected: any[]) => SinonMatcher;
                          • Requires an Array to contain each one of the values the given array has.

                          method deepEquals

                          deepEquals: (expected: any[]) => SinonMatcher;
                          • Requires an Array to be deep equal another one.

                          method endsWith

                          endsWith: (expected: any[]) => SinonMatcher;
                          • Requires an Array to end with the same values as another one.

                          method startsWith

                          startsWith: (expected: any[]) => SinonMatcher;
                          • Requires an Array to start with the same values as another one.

                          interface SinonAssert

                          interface SinonAssert {}

                            method alwaysCalledOn

                            alwaysCalledOn: (spy: SinonSpy<any>, obj: any) => void;
                            • Passes if spy was always called with obj as its this value.

                            method alwaysCalledWith

                            alwaysCalledWith: <TArgs extends any[]>(
                            spy: SinonSpy<TArgs>,
                            ...args: MatchPartialArguments<TArgs>
                            ) => void;
                            • Passes if spy was always called with the provided arguments.

                              Parameter spy

                              Parameter args

                            method alwaysCalledWithExactly

                            alwaysCalledWithExactly: <TArgs extends any[]>(
                            spy: SinonSpy<TArgs>,
                            ...args: MatchExactArguments<TArgs>
                            ) => void;
                            • Passes if spy was always called with the provided arguments and no others.

                            method alwaysCalledWithMatch

                            alwaysCalledWithMatch: <TArgs extends any[]>(
                            spy: SinonSpy<TArgs>,
                            ...args: MatchPartialArguments<TArgs>
                            ) => void;
                            • Passes if spy was always called with matching arguments. This behaves the same way as sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).

                            method alwaysThrew

                            alwaysThrew: {
                            (spy: SinonSpy<any>): void;
                            (spy: SinonSpy<any, any>, exception: string): void;
                            (spy: SinonSpy<any, any>, exception: any): void;
                            };
                            • Like threw, only required for all calls to the spy.

                            method callCount

                            callCount: (spy: SinonSpy<any>, count: number) => void;
                            • Passes if spy was called exactly num times.

                            method called

                            called: (spy: SinonSpy<any>) => void;
                            • Passes if spy was called at least once.

                            method calledOn

                            calledOn: (spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>, obj: any) => void;
                            • Passes if spy was ever called with obj as its this value. It’s possible to assert on a dedicated spy call: sinon.assert.calledOn(spy.firstCall, arg1, arg2, ...);.

                            method calledOnce

                            calledOnce: (spy: SinonSpy<any>) => void;
                            • Passes if spy was called once and only once.

                            method calledOnceWithExactly

                            calledOnceWithExactly: <TArgs extends any[]>(
                            spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
                            ...args: MatchExactArguments<TArgs>
                            ) => void;
                            • Passes if spy was called at exactly once with the provided arguments and no others.

                              Parameter spyOrSpyCall

                              Parameter args

                            method calledOnceWithMatch

                            calledOnceWithMatch: <TArgs extends any[]>(
                            spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
                            ...args: MatchPartialArguments<TArgs>
                            ) => void;
                            • Passes if spy was called once with matching arguments. This behaves the same way as calling both sinon.assert.calledOnce(spy) and sinon.assert.calledWithMatch(spy, ...).

                            method calledThrice

                            calledThrice: (spy: SinonSpy<any>) => void;
                            • Passes if spy was called exactly three times.

                            method calledTwice

                            calledTwice: (spy: SinonSpy<any>) => void;
                            • Passes if spy was called exactly twice.

                            method calledWith

                            calledWith: <TArgs extends any[]>(
                            spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
                            ...args: MatchPartialArguments<TArgs>
                            ) => void;
                            • Passes if spy was called with the provided arguments. It’s possible to assert on a dedicated spy call: sinon.assert.calledWith(spy.firstCall, arg1, arg2, ...);.

                              Parameter spyOrSpyCall

                              Parameter args

                            method calledWithExactly

                            calledWithExactly: <TArgs extends any[]>(
                            spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
                            ...args: MatchExactArguments<TArgs>
                            ) => void;
                            • Passes if spy was called with the provided arguments and no others. It’s possible to assert on a dedicated spy call: sinon.assert.calledWithExactly(spy.getCall(1), arg1, arg2, ...);.

                              Parameter spyOrSpyCall

                              Parameter args

                            method calledWithMatch

                            calledWithMatch: <TArgs extends any[]>(
                            spyOrSpyCall: SinonSpy<TArgs> | SinonSpyCall<TArgs>,
                            ...args: MatchPartialArguments<TArgs>
                            ) => void;
                            • Passes if spy was called with matching arguments. This behaves the same way as sinon.assert.calledWith(spy, sinon.match(arg1), sinon.match(arg2), ...). It's possible to assert on a dedicated spy call: sinon.assert.calledWithMatch(spy.secondCall, arg1, arg2, ...);.

                            method calledWithNew

                            calledWithNew: (spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>) => void;
                            • Passes if spy was called with the new operator. It’s possible to assert on a dedicated spy call: sinon.assert.calledWithNew(spy.secondCall, arg1, arg2, ...);.

                              Parameter spyOrSpyCall

                            method callOrder

                            callOrder: (...spies: Array<SinonSpy<any>>) => void;
                            • Passes if provided spies were called in the specified order.

                              Parameter spies

                            method expose

                            expose: (obj: any, options?: Partial<SinonExposeOptions>) => void;
                            • Exposes assertions into another object, to better integrate with the test framework. For instance, JsTestDriver uses global assertions, and to make Sinon.JS assertions appear alongside them, you can do.

                              Example 1

                              sinon.assert.expose(this); This will give you assertCalled(spy),assertCallOrder(spy1, spy2, ...) and so on. The method accepts an optional options object with two options.

                            method fail

                            fail: (message?: string) => void;
                            • Every assertion fails by calling this method. If your testing framework of choice looks for assertion errors by checking for a specific exception, you can override the fail method to do the right thing.

                            method match

                            match: (actual: any, expected: any) => void;
                            • Uses sinon.match to test if the arguments can be considered a match.

                            method neverCalledWith

                            neverCalledWith: <TArgs extends any[]>(
                            spy: SinonSpy<TArgs>,
                            ...args: MatchPartialArguments<TArgs>
                            ) => void;
                            • Passes if spy was never called with the provided arguments.

                              Parameter spy

                              Parameter args

                            method neverCalledWithMatch

                            neverCalledWithMatch: <TArgs extends any[]>(
                            spy: SinonSpy<TArgs>,
                            ...args: MatchPartialArguments<TArgs>
                            ) => void;
                            • Passes if spy was never called with matching arguments. This behaves the same way as sinon.assert.neverCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).

                              Parameter spy

                              Parameter args

                            method notCalled

                            notCalled: (spy: SinonSpy<any>) => void;
                            • Passes if spy was never called

                              Parameter spy

                            method pass

                            pass: (assertion: any) => void;
                            • Called every time assertion passes. Default implementation does nothing.

                            method threw

                            threw: {
                            (spyOrSpyCall: SinonSpy<any> | SinonSpyCall<any>): void;
                            (
                            spyOrSpyCall: SinonSpyCall<any, any> | SinonSpy<any, any>,
                            exception: string
                            ): void;
                            (
                            spyOrSpyCall: SinonSpyCall<any, any> | SinonSpy<any, any>,
                            exception: any
                            ): void;
                            };
                            • Passes if spy threw any exception.

                            • Passes if spy threw the given exception. The exception is an actual object. It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.

                            • Passes if spy threw the given exception. The exception is a String denoting its type. It’s possible to assert on a dedicated spy call: sinon.assert.threw(spy.thirdCall, exception);.

                            interface SinonExpectation

                            interface SinonExpectation extends SinonStub {}

                              method atLeast

                              atLeast: (n: number) => SinonExpectation;
                              • Specify the minimum amount of calls expected.

                              method atMost

                              atMost: (n: number) => SinonExpectation;
                              • Specify the maximum amount of calls expected.

                                Parameter n

                              method exactly

                              exactly: (n: number) => SinonExpectation;
                              • Expect the method to be called exactly

                                Parameter n

                                times.

                              method never

                              never: () => SinonExpectation;
                              • Expect the method to never be called.

                              method on

                              on: (obj: any) => SinonExpectation;

                                method once

                                once: () => SinonExpectation;
                                • Expect the method to be called exactly once.

                                method restore

                                restore: () => void;
                                • Restores all mocked methods.

                                method thrice

                                thrice: () => SinonExpectation;
                                • Expect the method to be called exactly thrice.

                                method twice

                                twice: () => SinonExpectation;
                                • Expect the method to be called exactly twice.

                                method verify

                                verify: () => SinonExpectation;
                                • Verifies all expectations on the mock. If any expectation is not satisfied, an exception is thrown. Also restores the mocked methods.

                                method withArgs

                                withArgs: (...args: any[]) => SinonExpectation;
                                • Expect the method to be called with the provided arguments and possibly others. An expectation instance only holds onto a single set of arguments specified with withArgs. Subsequent calls will overwrite the previously-specified set of arguments (even if they are different), so it is generally not intended that this method be invoked more than once per test case.

                                  Parameter args

                                method withExactArgs

                                withExactArgs: (...args: any[]) => SinonExpectation;
                                • Expect the method to be called with the provided arguments and no others. An expectation instance only holds onto a single set of arguments specified with withExactArgs. Subsequent calls will overwrite the previously-specified set of arguments (even if they are different), so it is generally not intended that this method be invoked more than once per test case.

                                  Parameter args

                                interface SinonExpectationStatic

                                interface SinonExpectationStatic {}

                                  method create

                                  create: (methodName?: string) => SinonExpectation;
                                  • Creates an expectation without a mock object, basically an anonymous mock function. Method name is optional and is used in exception messages to make them more readable.

                                    Parameter methodName

                                  interface SinonExposeOptions

                                  interface SinonExposeOptions {}

                                    property includeFail

                                    includeFail: boolean;

                                      property prefix

                                      prefix: string;

                                        interface SinonFake

                                        interface SinonFake {}

                                          method rejects

                                          rejects: <TArgs extends readonly any[] = any[], TReturnValue = any>(
                                          val: any
                                          ) => SinonSpy<TArgs, TReturnValue>;
                                          • Creates a fake that returns a rejected Promise for the passed value. If an Error is passed as the value argument, then that will be the value of the promise. If any other value is passed, then that will be used for the message property of the Error returned by the promise.

                                            Parameter val

                                            Rejected promise

                                          method resolves

                                          resolves: <TArgs extends readonly any[] = any[], TReturnValue = any>(
                                          val: TReturnValue extends PromiseLike<infer TResolveValue>
                                          ? TResolveValue
                                          : any
                                          ) => SinonSpy<TArgs, TReturnValue>;
                                          • Creates a fake that returns a resolved Promise for the passed value.

                                            Parameter val

                                            Resolved promise

                                          method returns

                                          returns: <TArgs extends readonly any[] = any[], TReturnValue = any>(
                                          val: TReturnValue
                                          ) => SinonSpy<TArgs, TReturnValue>;
                                          • Creates a fake that returns the val argument

                                            Parameter val

                                            Returned value

                                          method throws

                                          throws: <TArgs extends readonly any[] = any[], TReturnValue = any>(
                                          val: Error | string
                                          ) => SinonSpy<TArgs, TReturnValue>;
                                          • Creates a fake that throws an Error with the provided value as the message property. If an Error is passed as the val argument, then that will be the thrown value. If any other value is passed, then that will be used for the message property of the thrown Error.

                                            Parameter val

                                            Returned value or throw value if an Error

                                          method yields

                                          yields: <TArgs extends readonly any[] = any[], TReturnValue = any>(
                                          ...args: any[]
                                          ) => SinonSpy<TArgs, TReturnValue>;
                                          • fake expects the last argument to be a callback and will invoke it with the given arguments.

                                          method yieldsAsync

                                          yieldsAsync: <TArgs extends readonly any[] = any[], TReturnValue = any>(
                                          ...args: any[]
                                          ) => SinonSpy<TArgs, TReturnValue>;
                                          • fake expects the last argument to be a callback and will invoke it asynchronously with the given arguments.

                                          call signature

                                          <TArgs extends readonly any[] = any[], TReturnValue = any>(): SinonSpy<
                                          TArgs,
                                          TReturnValue
                                          >;
                                          • Creates a basic fake, with no behavior

                                          call signature

                                          <TArgs extends readonly any[] = any[], TReturnValue = any>(
                                          fn: (...args: TArgs) => TReturnValue
                                          ): SinonSpy<TArgs, TReturnValue>;
                                          • Wraps an existing Function to record all interactions, while leaving it up to the func to provide the behavior. This is useful when complex behavior not covered by the sinon.fake.* methods is required or when wrapping an existing function or method.

                                          interface SinonFakeUploadProgress

                                          interface SinonFakeUploadProgress {}

                                            property eventListeners

                                            eventListeners: {
                                            progress: any[];
                                            load: any[];
                                            abort: any[];
                                            error: any[];
                                            };

                                              method addEventListener

                                              addEventListener: (event: string, listener: (e: Event) => any) => void;

                                                method dispatchEvent

                                                dispatchEvent: (event: Event) => void;

                                                  method removeEventListener

                                                  removeEventListener: (event: string, listener: (e: Event) => any) => void;

                                                    interface SinonMapMatcher

                                                    interface SinonMapMatcher extends SinonMatcher {}

                                                      method contains

                                                      contains: (expected: SimplifiedMap) => SinonMatcher;
                                                      • Requires a Map to contain each one of the items the given map has.

                                                      method deepEquals

                                                      deepEquals: (expected: SimplifiedMap) => SinonMatcher;
                                                      • Requires a Map to be deep equal another one.

                                                      interface SinonMatch

                                                      interface SinonMatch {}

                                                        property any

                                                        any: SinonMatcher;
                                                        • Matches anything.

                                                        property array

                                                        array: SinonArrayMatcher;
                                                        • Requires the value to be an Array.

                                                        property bool

                                                        bool: SinonMatcher;
                                                        • Requires the value to be a Boolean

                                                        property date

                                                        date: SinonMatcher;
                                                        • Requires the value to be a Date object.

                                                        property defined

                                                        defined: SinonMatcher;
                                                        • Requires the value to be defined.

                                                        property falsy

                                                        falsy: SinonMatcher;
                                                        • Requires the value to be falsy.

                                                        property func

                                                        func: SinonMatcher;
                                                        • Requires the value to be a Function.

                                                        property map

                                                        map: SinonMapMatcher;
                                                        • Requires the value to be a Map.

                                                        property number

                                                        number: SinonMatcher;
                                                        • Requires the value to be a Number.

                                                        property object

                                                        object: SinonMatcher;
                                                        • Requires the value to be an Object.

                                                        property regexp

                                                        regexp: SinonMatcher;
                                                        • Requires the value to be a regular expression.

                                                        property set

                                                        set: SinonSetMatcher;
                                                        • Requires the value to be a Set.

                                                        property string

                                                        string: SinonMatcher;
                                                        • Requires the value to be a String.

                                                        property symbol

                                                        symbol: SinonMatcher;
                                                        • Requires the value to be a Symbol.

                                                        property truthy

                                                        truthy: SinonMatcher;
                                                        • Requires the value to be truthy.

                                                        method every

                                                        every: (matcher: SinonMatcher) => SinonMatcher;
                                                        • Requires every element of an Array, Set or Map, or alternatively every value of an Object to match the given matcher.

                                                        method has

                                                        has: (property: string, expect?: any) => SinonMatcher;
                                                        • Requires the value to define the given property. The property might be inherited via the prototype chain. If the optional expectation is given, the value of the property is deeply compared with the expectation. The expectation can be another matcher.

                                                          Parameter property

                                                          Parameter expect

                                                        method hasNested

                                                        hasNested: (path: string, expect?: any) => SinonMatcher;
                                                        • Requires the value to define the given propertyPath. Dot (prop.prop) and bracket (prop[0]) notations are supported as in Lodash.get. The propertyPath might be inherited via the prototype chain. If the optional expectation is given, the value at the propertyPath is deeply compared with the expectation. The expectation can be another matcher.

                                                        method hasOwn

                                                        hasOwn: (property: string, expect?: any) => SinonMatcher;
                                                        • Same as sinon.match.has but the property must be defined by the value itself. Inherited properties are ignored.

                                                          Parameter property

                                                          Parameter expect

                                                        method in

                                                        in: (allowed: any[]) => SinonMatcher;
                                                        • Requires the value to be in the specified array.

                                                        method instanceOf

                                                        instanceOf: (type: any) => SinonMatcher;
                                                        • Requires the value to be an instance of the given type.

                                                        method same

                                                        same: (obj: any) => SinonMatcher;
                                                        • Requires the value to strictly equal ref.

                                                        method some

                                                        some: (matcher: SinonMatcher) => SinonMatcher;
                                                        • Requires any element of an Array, Set or Map, or alternatively any value of an Object to match the given matcher.

                                                        method typeOf

                                                        typeOf: (type: string) => SinonMatcher;
                                                        • Requires the value to be of the given type, where type can be one of "undefined", "null", "boolean", "number", "string", "object", "function", "array", "regexp", "date" or "symbol".

                                                        call signature

                                                        (value: number): SinonMatcher;
                                                        • Requires the value to be == to the given number.

                                                        call signature

                                                        (value: string): SinonMatcher;
                                                        • Requires the value to be a string and have the expectation as a substring.

                                                        call signature

                                                        (expr: RegExp): SinonMatcher;
                                                        • Requires the value to be a string and match the given regular expression.

                                                        call signature

                                                        (callback: (value: any) => boolean, message?: string): SinonMatcher;
                                                        • See custom matchers.

                                                        call signature

                                                        (obj: object): SinonMatcher;
                                                        • Requires the value to be not null or undefined and have at least the same properties as expectation. This supports nested matchers.

                                                        interface SinonMatcher

                                                        interface SinonMatcher {}

                                                          method and

                                                          and: (expr: SinonMatcher) => SinonMatcher;
                                                          • All matchers implement and and or. This allows to logically combine mutliple matchers. The result is a new matchers that requires both (and) or one of the matchers (or) to return true.

                                                            Example 1

                                                            var stringOrNumber = sinon.match.string.or(sinon.match.number); var bookWithPages = sinon.match.instanceOf(Book).and(sinon.match.has("pages"));

                                                          method or

                                                          or: (expr: SinonMatcher) => SinonMatcher;
                                                          • All matchers implement and and or. This allows to logically combine mutliple matchers. The result is a new matchers that requires both (and) or one of the matchers (or) to return true.

                                                            Example 1

                                                            var stringOrNumber = sinon.match.string.or(sinon.match.number); var bookWithPages = sinon.match.instanceOf(Book).and(sinon.match.has("pages"));

                                                          method test

                                                          test: (val: any) => boolean;

                                                            interface SinonMock

                                                            interface SinonMock {}

                                                              method expects

                                                              expects: (method: string) => SinonExpectation;
                                                              • Overrides obj.method with a mock function and returns it.

                                                              method restore

                                                              restore: () => void;
                                                              • Restores all mocked methods.

                                                              method verify

                                                              verify: () => void;
                                                              • Verifies all expectations on the mock. If any expectation is not satisfied, an exception is thrown. Also restores the mocked methods.

                                                              interface SinonMockStatic

                                                              interface SinonMockStatic {}

                                                                call signature

                                                                (name?: string): SinonExpectation;

                                                                  call signature

                                                                  (obj: any): SinonMock;
                                                                  • Creates a mock for the provided object. Does not change the object, but returns a mock object to set expectations on the object’s methods.

                                                                  interface SinonSandbox

                                                                  interface SinonSandbox {}

                                                                    property assert

                                                                    assert: SinonAssert;
                                                                    • A convenience reference for sinon.assert Since sinon@2.0.0

                                                                    property clock

                                                                    clock: SinonFakeTimers;

                                                                      property fake

                                                                      fake: SinonFake;

                                                                        property match

                                                                        match: SinonMatch;

                                                                          property mock

                                                                          mock: SinonMockStatic;
                                                                          • Works exactly like sinon.mock

                                                                          property replace

                                                                          replace: SandboxReplace;

                                                                            property spy

                                                                            spy: SinonSpyStatic;
                                                                            • Works exactly like sinon.spy

                                                                            property stub

                                                                            stub: SinonStubStatic;
                                                                            • Works exactly like sinon.stub.

                                                                            method createStubInstance

                                                                            createStubInstance: <TType>(
                                                                            constructor: StubbableType<TType>,
                                                                            overrides?: {
                                                                            [K in keyof TType]?:
                                                                            | SinonStubbedMember<TType[K]>
                                                                            | (TType[K] extends (...args: any[]) => infer R ? R : TType[K]);
                                                                            }
                                                                            ) => SinonStubbedInstance<TType>;
                                                                            • Creates a new object with the given functions as the prototype and stubs all implemented functions.

                                                                              TType Type being stubbed.

                                                                              Parameter constructor

                                                                              Object or class to stub.

                                                                              Parameter overrides

                                                                              An optional map overriding created stubs

                                                                              Returns

                                                                              A stubbed version of the constructor.

                                                                              Remarks

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

                                                                            method define

                                                                            define: (obj: object, key: PropertyKey, value: unknown) => void;
                                                                            • Defines a property on the given object which will be torn down when the sandbox is restored

                                                                            method replaceGetter

                                                                            replaceGetter: <T, TKey extends keyof T>(
                                                                            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.

                                                                              Parameter obj

                                                                              Parameter prop

                                                                              Parameter replacement

                                                                            method replaceSetter

                                                                            replaceSetter: <T, TKey extends keyof T>(
                                                                            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.

                                                                              Parameter obj

                                                                              Parameter prop

                                                                              Parameter replacement

                                                                            method reset

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

                                                                            method resetBehavior

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

                                                                            method resetHistory

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

                                                                            method restore

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

                                                                            method useFakeTimers

                                                                            useFakeTimers: (
                                                                            config?: number | Date | Partial<FakeTimers.FakeTimerInstallOpts>
                                                                            ) => SinonFakeTimers;
                                                                            • * 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 'fake-timers' with the specified unix epoch (default: 0) * config.toFake - String[ ] - an array with explicit function names to fake. By default fake-timers will automatically fake _all_ methods (changed in v19). * config.shouldAdvanceTime - Boolean - tells fake-timers to increment mocked time automatically based on the real system time shift (default: false). When used in conjunction with config.toFake, it will only work if 'setInterval' is included in config.toFake. * Important note: when faking nextTick, normal calls to process.nextTick() will 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() manually (see example below). You can easily work around this using the config.toFake option. Please refer to the [fake-timers](https://github.com/sinonjs/fake-timers) documentation for more information.

                                                                              Parameter config

                                                                            method verify

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

                                                                            method verifyAndRestore

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

                                                                            interface SinonSandboxConfig

                                                                            interface SinonSandboxConfig {}

                                                                              property assertOptions

                                                                              assertOptions: {
                                                                              shouldLimitAssertionLogs?: boolean;
                                                                              assertionLogLimit?: number;
                                                                              };
                                                                              • The assert options can help limit the amount of output produced by assert.fail

                                                                              property injectInto

                                                                              injectInto: object | null;
                                                                              • The sandbox’s methods can be injected into another object for convenience. The injectInto configuration option can name an object to add properties to.

                                                                              property properties

                                                                              properties: string[];
                                                                              • Which properties to inject into the facade object. By default empty!

                                                                              property useFakeTimers

                                                                              useFakeTimers: boolean | Partial<FakeTimers.FakeTimerInstallOpts>;
                                                                              • If set to true, the sandbox will have a clock property. You can optionally pass in a configuration object that follows the specification for fake timers, such as { toFake: ["setTimeout", "setInterval"] }.

                                                                              interface SinonSetMatcher

                                                                              interface SinonSetMatcher extends SinonMatcher {}

                                                                                method contains

                                                                                contains: (expected: SimplifiedSet) => SinonMatcher;
                                                                                • Requires a Set to contain each one of the items the given set has.

                                                                                method deepEquals

                                                                                deepEquals: (expected: SimplifiedSet) => SinonMatcher;
                                                                                • Requires a Set to be deep equal another one.

                                                                                interface SinonSpy

                                                                                interface SinonSpy<TArgs extends readonly any[] = any[], TReturnValue = any>
                                                                                extends Pick<
                                                                                SinonSpyCallApi<TArgs, TReturnValue>,
                                                                                Exclude<keyof SinonSpyCallApi<TArgs, TReturnValue>, 'args'>
                                                                                > {}

                                                                                  property args

                                                                                  args: TArgs[];
                                                                                  • Array of arguments received, spy.args[0] is an array of arguments received in the first call.

                                                                                  property callCount

                                                                                  callCount: number;
                                                                                  • The number of recorded calls.

                                                                                  property called

                                                                                  called: boolean;
                                                                                  • true if the spy was called at least once

                                                                                  property calledOnce

                                                                                  calledOnce: boolean;
                                                                                  • true if spy was called exactly once

                                                                                  property calledThrice

                                                                                  calledThrice: boolean;
                                                                                  • true if the spy was called exactly thrice

                                                                                  property calledTwice

                                                                                  calledTwice: boolean;
                                                                                  • true if the spy was called exactly twice

                                                                                  property exceptions

                                                                                  exceptions: any[];
                                                                                  • Array of exception objects thrown, spy.exceptions[0] is the exception thrown by the first call. If the call did not throw an error, the value at the call’s location in .exceptions will be undefined.

                                                                                  property firstCall

                                                                                  firstCall: SinonSpyCall<TArgs, TReturnValue>;
                                                                                  • The first call

                                                                                  property lastCall

                                                                                  lastCall: SinonSpyCall<TArgs, TReturnValue>;
                                                                                  • The last call

                                                                                  property notCalled

                                                                                  notCalled: boolean;
                                                                                  • true if the spy was not called

                                                                                  property returnValues

                                                                                  returnValues: TReturnValue[];
                                                                                  • Array of return values, spy.returnValues[0] is the return value of the first call. If the call did not explicitly return a value, the value at the call’s location in .returnValues will be undefined.

                                                                                  property secondCall

                                                                                  secondCall: SinonSpyCall<TArgs, TReturnValue>;
                                                                                  • The second call

                                                                                  property thirdCall

                                                                                  thirdCall: SinonSpyCall<TArgs, TReturnValue>;
                                                                                  • The third call

                                                                                  property thisValues

                                                                                  thisValues: any[];
                                                                                  • Array of this objects, spy.thisValues[0] is the this object for the first call.

                                                                                  property wrappedMethod

                                                                                  wrappedMethod: (...args: TArgs) => TReturnValue;
                                                                                  • Holds a reference to the original method/function this stub has wrapped.

                                                                                  method alwaysCalledOn

                                                                                  alwaysCalledOn: (obj: any) => boolean;
                                                                                  • Returns true if the spy was always called with

                                                                                    Parameter obj

                                                                                    as this.

                                                                                    Parameter obj

                                                                                  method alwaysCalledWith

                                                                                  alwaysCalledWith: (...args: MatchExactArguments<TArgs>) => boolean;
                                                                                  • Returns true if spy was always called with the provided arguments (and possibly others).

                                                                                  method alwaysCalledWithExactly

                                                                                  alwaysCalledWithExactly: (...args: MatchExactArguments<TArgs>) => boolean;
                                                                                  • Returns true if spy was always called with the exact provided arguments.

                                                                                    Parameter args

                                                                                  method alwaysCalledWithMatch

                                                                                  alwaysCalledWithMatch: (...args: TArgs) => boolean;
                                                                                  • Returns true if spy was always called with matching arguments (and possibly others). This behaves the same as spy.alwaysCalledWith(sinon.match(arg1), sinon.match(arg2), ...).

                                                                                    Parameter args

                                                                                  method alwaysReturned

                                                                                  alwaysReturned: (obj: any) => boolean;
                                                                                  • Returns true if spy always returned the provided value.

                                                                                    Parameter obj

                                                                                  method alwaysThrew

                                                                                  alwaysThrew: { (): boolean; (type: string): boolean; (obj: any): boolean };
                                                                                  • Returns true if spy always threw an exception.

                                                                                  • Returns true if spy always threw an exception of the provided type.

                                                                                  • Returns true if spy always threw the provided exception object.

                                                                                  method calledAfter

                                                                                  calledAfter: (anotherSpy: SinonSpy<any>) => boolean;
                                                                                  • Returns true if the spy was called after

                                                                                    Parameter anotherSpy

                                                                                    Parameter anotherSpy

                                                                                  method calledBefore

                                                                                  calledBefore: (anotherSpy: SinonSpy<any>) => boolean;
                                                                                  • Returns true if the spy was called before

                                                                                    Parameter anotherSpy

                                                                                    Parameter anotherSpy

                                                                                  method calledImmediatelyAfter

                                                                                  calledImmediatelyAfter: (anotherSpy: SinonSpy<any>) => boolean;
                                                                                  • Returns true if spy was called after

                                                                                    Parameter anotherSpy

                                                                                    , and no spy calls occurred between

                                                                                    Parameter anotherSpy

                                                                                    and spy.

                                                                                    Parameter anotherSpy

                                                                                  method calledImmediatelyBefore

                                                                                  calledImmediatelyBefore: (anotherSpy: SinonSpy<any>) => boolean;
                                                                                  • Returns true if spy was called before

                                                                                    Parameter anotherSpy

                                                                                    , and no spy calls occurred between spy and

                                                                                    Parameter

                                                                                    anotherSpy.

                                                                                    Parameter anotherSpy

                                                                                  method getCall

                                                                                  getCall: (n: number) => SinonSpyCall<TArgs, TReturnValue>;
                                                                                  • Returns the nth call. Accessing individual calls helps with more detailed behavior verification when the spy is called more than once.

                                                                                    Parameter n

                                                                                    Zero-based index of the spy call.

                                                                                  method getCalls

                                                                                  getCalls: () => Array<SinonSpyCall<TArgs, TReturnValue>>;
                                                                                  • Returns an Array of all calls recorded by the spy.

                                                                                  method invokeCallback

                                                                                  invokeCallback: (...args: TArgs) => void;
                                                                                  • Invoke callbacks passed to the stub with the given arguments. If the stub was never called with a function argument, yield throws an error. Returns an Array with all callbacks return values in the order they were called, if no error is thrown.

                                                                                  method named

                                                                                  named: (name: string) => SinonSpy<TArgs, TReturnValue>;
                                                                                  • Set the displayName of the spy or stub.

                                                                                    Parameter name

                                                                                  method neverCalledWith

                                                                                  neverCalledWith: (...args: MatchExactArguments<TArgs>) => boolean;
                                                                                  • Returns true if the spy/stub was never called with the provided arguments.

                                                                                    Parameter args

                                                                                  method neverCalledWithMatch

                                                                                  neverCalledWithMatch: (...args: TArgs) => boolean;
                                                                                  • Returns true if the spy/stub was never called with matching arguments. This behaves the same as spy.neverCalledWith(sinon.match(arg1), sinon.match(arg2), ...).

                                                                                    Parameter args

                                                                                  method printf

                                                                                  printf: (format: string, ...args: any[]) => string;
                                                                                  • Returns the passed format string with the following replacements performed: * %n - the name of the spy "spy" by default) * %c - the number of times the spy was called, in words ("once", "twice", etc.) * %C - a list of string representations of the calls to the spy, with each call prefixed by a newline and four spaces * %t - a comma-delimited list of this values the spy was called on * %n - the formatted value of the nth argument passed to printf * %* - a comma-delimited list of the (non-format string) arguments passed to printf * %D - a multi-line list of the arguments received by all calls to the spy

                                                                                    Parameter format

                                                                                    Parameter args

                                                                                  method resetHistory

                                                                                  resetHistory: () => void;
                                                                                  • Resets the state of a spy.

                                                                                  method restore

                                                                                  restore: () => void;
                                                                                  • Replaces the spy with the original method. Only available if the spy replaced an existing method.

                                                                                  method withArgs

                                                                                  withArgs: (
                                                                                  ...args: MatchPartialArguments<TArgs>
                                                                                  ) => SinonSpy<TArgs, TReturnValue>;
                                                                                  • Creates a spy that only records calls when the received arguments match those passed to withArgs. This is useful to be more expressive in your assertions, where you can access the spy with the same call.

                                                                                    Parameter args

                                                                                    Expected args

                                                                                  call signature

                                                                                  (...args: TArgs): TReturnValue;

                                                                                    interface SinonSpyCall

                                                                                    interface SinonSpyCall<TArgs extends readonly any[] = any[], TReturnValue = any>
                                                                                    extends SinonSpyCallApi<TArgs, TReturnValue> {}

                                                                                      property callback

                                                                                      callback: Function | undefined;
                                                                                      • This property is a convenience for a call’s callback. When the last argument in a call is a Function, then callback will reference that. Otherwise it will be undefined.

                                                                                      property exception

                                                                                      exception: any;
                                                                                      • Exception thrown, if any.

                                                                                      property firstArg

                                                                                      firstArg: any;
                                                                                      • This property is a convenience for the first argument of the call.

                                                                                      property lastArg

                                                                                      lastArg: any;
                                                                                      • This property is a convenience for the last argument of the call.

                                                                                      property returnValue

                                                                                      returnValue: TReturnValue;
                                                                                      • Return value.

                                                                                      property thisValue

                                                                                      thisValue: any;
                                                                                      • The call’s this value.

                                                                                      method calledAfter

                                                                                      calledAfter: (call: SinonSpyCall<any>) => boolean;
                                                                                      • Returns true if the spy call occurred after another spy call.

                                                                                        Parameter call

                                                                                      method calledBefore

                                                                                      calledBefore: (call: SinonSpyCall<any>) => boolean;
                                                                                      • Returns true if the spy call occurred before another spy call.

                                                                                        Parameter call

                                                                                      interface SinonSpyCallApi

                                                                                      interface SinonSpyCallApi<
                                                                                      TArgs extends readonly any[] = any[],
                                                                                      TReturnValue = any
                                                                                      > {}

                                                                                        property args

                                                                                        args: TArgs;
                                                                                        • Array of received arguments.

                                                                                        method callArg

                                                                                        callArg: (pos: number) => unknown[];
                                                                                        • Like yield, but with an explicit argument number specifying which callback to call. Useful if a function is called with more than one callback, and simply calling the first callback is not desired.

                                                                                          Parameter pos

                                                                                        method callArgOn

                                                                                        callArgOn: (pos: number, obj: any, ...args: any[]) => unknown[];

                                                                                          method callArgOnWith

                                                                                          callArgOnWith: (pos: number, obj: any, ...args: any[]) => unknown[];

                                                                                            method callArgWith

                                                                                            callArgWith: (pos: number, ...args: any[]) => unknown[];
                                                                                            • Like callArg, but with arguments.

                                                                                            method calledOn

                                                                                            calledOn: (obj: any) => boolean;
                                                                                            • Returns true if the spy was called at least once with

                                                                                              Parameter obj

                                                                                              as this. calledOn also accepts a matcher spyCall.calledOn(sinon.match(fn)) (see matchers).

                                                                                              Parameter obj

                                                                                            method calledOnceWith

                                                                                            calledOnceWith: (...args: MatchPartialArguments<TArgs>) => boolean;
                                                                                            • Returns true if spy was called at exactly once with the provided arguments.

                                                                                              Parameter args

                                                                                            method calledOnceWithExactly

                                                                                            calledOnceWithExactly: (...args: MatchExactArguments<TArgs>) => boolean;

                                                                                              method calledWith

                                                                                              calledWith: (...args: MatchPartialArguments<TArgs>) => boolean;
                                                                                              • Returns true if spy was called at least once with the provided arguments. Can be used for partial matching, Sinon only checks the provided arguments against actual arguments, so a call that received the provided arguments (in the same spots) and possibly others as well will return true.

                                                                                                Parameter args

                                                                                              method calledWithExactly

                                                                                              calledWithExactly: (...args: MatchExactArguments<TArgs>) => boolean;
                                                                                              • Returns true if spy was called at least once with the provided arguments and no others.

                                                                                              method calledWithMatch

                                                                                              calledWithMatch: (...args: MatchPartialArguments<TArgs>) => boolean;
                                                                                              • Returns true if spy was called with matching arguments (and possibly others). This behaves the same as spy.calledWith(sinon.match(arg1), sinon.match(arg2), ...).

                                                                                                Parameter args

                                                                                              method calledWithNew

                                                                                              calledWithNew: () => boolean;
                                                                                              • Returns true if spy/stub was called the new operator. Beware that this is inferred based on the value of the this object and the spy function’s prototype, so it may give false positives if you actively return the right kind of object.

                                                                                              method notCalledWith

                                                                                              notCalledWith: (...args: MatchExactArguments<TArgs>) => boolean;
                                                                                              • Returns true if call did not receive provided arguments.

                                                                                                Parameter args

                                                                                              method notCalledWithMatch

                                                                                              notCalledWithMatch: (...args: MatchPartialArguments<TArgs>) => boolean;
                                                                                              • Returns true if call did not receive matching arguments. This behaves the same as spyCall.notCalledWith(sinon.match(arg1), sinon.match(arg2), ...).

                                                                                                Parameter args

                                                                                              method returned

                                                                                              returned: (value: TReturnValue | SinonMatcher) => boolean;
                                                                                              • Returns true if spy returned the provided value at least once. Uses deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj)) for strict comparison (see matchers).

                                                                                                Parameter value

                                                                                              method threw

                                                                                              threw: { (): boolean; (type: string): boolean; (obj: any): boolean };
                                                                                              • Returns true if spy threw an exception at least once.

                                                                                              • Returns true if spy threw an exception of the provided type at least once.

                                                                                              • Returns true if spy threw the provided exception object at least once.

                                                                                              method yield

                                                                                              yield: (...args: any[]) => unknown[];
                                                                                              • Invoke callbacks passed to the stub with the given arguments. If the stub was never called with a function argument, yield throws an error. Returns an Array with all callbacks return values in the order they were called, if no error is thrown. Also aliased as invokeCallback.

                                                                                              method yieldOn

                                                                                              yieldOn: (obj: any, ...args: any[]) => unknown[];

                                                                                                method yieldTo

                                                                                                yieldTo: (property: string, ...args: any[]) => unknown[];
                                                                                                • Invokes callbacks passed as a property of an object to the stub. Like yield, yieldTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.

                                                                                                method yieldToOn

                                                                                                yieldToOn: (property: string, obj: any, ...args: any[]) => unknown[];

                                                                                                  interface SinonSpyStatic

                                                                                                  interface SinonSpyStatic {}

                                                                                                    call signature

                                                                                                    (): SinonSpy;
                                                                                                    • Creates an anonymous function that records arguments, this value, exceptions and return values for all calls.

                                                                                                    call signature

                                                                                                    <F extends (...args: any[]) => any>(func: F): SinonSpy<
                                                                                                    Parameters<F>,
                                                                                                    ReturnType<F>
                                                                                                    >;
                                                                                                    • Spies on the provided function

                                                                                                    call signature

                                                                                                    <T>(obj: T): SinonSpiedInstance<T>;
                                                                                                    • Spies on all the object’s methods.

                                                                                                    call signature

                                                                                                    <T, K extends keyof T>(obj: T, method: K): T[K] extends (
                                                                                                    ...args: infer TArgs
                                                                                                    ) => infer TReturnValue
                                                                                                    ? SinonSpy<TArgs, TReturnValue>
                                                                                                    : SinonSpy;
                                                                                                    • Creates a spy for object.method and replaces the original method with the spy. An exception is thrown if the property is not already a function. The spy acts exactly like the original method in all cases. The original method can be restored by calling object.method.restore(). The returned spy is the function object which replaced the original method. spy === object.method.

                                                                                                    call signature

                                                                                                    <T, K extends keyof T>(
                                                                                                    obj: T,
                                                                                                    method: K,
                                                                                                    types: Array<'get' | 'set'>
                                                                                                    ): PropertyDescriptor & {
                                                                                                    get: SinonSpy<[], T[K]>;
                                                                                                    set: SinonSpy<[T[K]], void>;
                                                                                                    };

                                                                                                      interface SinonStub

                                                                                                      interface SinonStub<TArgs extends readonly any[] = any[], TReturnValue = any>
                                                                                                      extends SinonSpy<TArgs, TReturnValue> {}

                                                                                                        method callsArg

                                                                                                        callsArg: (index: number) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the stub to call the argument at the provided index as a callback function. stub.callsArg(0); causes the stub to call the first argument as a callback. If the argument at the provided index is not available or is not a function, a TypeError will be thrown.

                                                                                                        method callsArgAsync

                                                                                                        callsArgAsync: (index: number) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                          Parameter index

                                                                                                        method callsArgOn

                                                                                                        callsArgOn: (index: number, context: any) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Like stub.callsArg(index); but with an additional parameter to pass the this context.

                                                                                                          Parameter index

                                                                                                          Parameter context

                                                                                                        method callsArgOnAsync

                                                                                                        callsArgOnAsync: (index: number, context: any) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                          Parameter index

                                                                                                          Parameter context

                                                                                                        method callsArgOnWith

                                                                                                        callsArgOnWith: (
                                                                                                        index: number,
                                                                                                        context: any,
                                                                                                        ...args: any[]
                                                                                                        ) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Like above but with an additional parameter to pass the this context.

                                                                                                          Parameter index

                                                                                                          Parameter context

                                                                                                          Parameter args

                                                                                                        method callsArgOnWithAsync

                                                                                                        callsArgOnWithAsync: (
                                                                                                        index: number,
                                                                                                        context: any,
                                                                                                        ...args: any[]
                                                                                                        ) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                        method callsArgWith

                                                                                                        callsArgWith: (index: number, ...args: any[]) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Like callsArg, but with arguments to pass to the callback.

                                                                                                          Parameter index

                                                                                                          Parameter args

                                                                                                        method callsArgWithAsync

                                                                                                        callsArgWithAsync: (
                                                                                                        index: number,
                                                                                                        ...args: any[]
                                                                                                        ) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                        method callsFake

                                                                                                        callsFake: (
                                                                                                        func: (...args: TArgs) => TReturnValue
                                                                                                        ) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Makes the stub call the provided

                                                                                                          Parameter func

                                                                                                          when invoked.

                                                                                                          Parameter func

                                                                                                        method callThrough

                                                                                                        callThrough: () => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the original method wrapped into the stub to be called when none of the conditional stubs are matched.

                                                                                                        method get

                                                                                                        get: (func: () => any) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Replaces a new getter for this stub.

                                                                                                        method named

                                                                                                        named: (name: string) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Set the displayName of the spy or stub.

                                                                                                          Parameter name

                                                                                                        method onCall

                                                                                                        onCall: (n: number) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Defines the behavior of the stub on the

                                                                                                          Parameter n

                                                                                                          call. Useful for testing sequential interactions. There are methods onFirstCall, onSecondCall,onThirdCall to make stub definitions read more naturally. onCall can be combined with all of the behavior defining methods in this section. In particular, it can be used together with withArgs.

                                                                                                          Parameter n

                                                                                                          Zero-based index of the spy call.

                                                                                                        method onFirstCall

                                                                                                        onFirstCall: () => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Alias for stub.onCall(0);

                                                                                                        method onSecondCall

                                                                                                        onSecondCall: () => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Alias for stub.onCall(1);

                                                                                                        method onThirdCall

                                                                                                        onThirdCall: () => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Alias for stub.onCall(2);

                                                                                                        method rejects

                                                                                                        rejects: {
                                                                                                        (): SinonStub<TArgs, TReturnValue>;
                                                                                                        (errorType: string): SinonStub<TArgs, TReturnValue>;
                                                                                                        (value: any): SinonStub<TArgs, TReturnValue>;
                                                                                                        };
                                                                                                        • Causes the stub to return a Promise which rejects with an exception (Error). When constructing the Promise, sinon uses the Promise.reject method. You are responsible for providing a polyfill in environments which do not provide Promise. Since sinon@2.0.0

                                                                                                        • Causes the stub to return a Promise which rejects with an exception of the provided type. Since sinon@2.0.0

                                                                                                        • Causes the stub to return a Promise which rejects with the provided exception object. Since sinon@2.0.0

                                                                                                        method reset

                                                                                                        reset: () => void;
                                                                                                        • Resets both behaviour and history of the stub. This is equivalent to calling both stub.resetBehavior() and stub.resetHistory() Updated in sinon@2.0.0 Since sinon@5.0.0 As a convenience, you can apply stub.reset() to all stubs using sinon.reset()

                                                                                                        method resetBehavior

                                                                                                        resetBehavior: () => void;
                                                                                                        • Resets the stub’s behaviour to the default behaviour You can reset behaviour of all stubs using sinon.resetBehavior()

                                                                                                        method resolves

                                                                                                        resolves: (
                                                                                                        value?: TReturnValue extends PromiseLike<infer TResolveValue>
                                                                                                        ? TResolveValue
                                                                                                        : any
                                                                                                        ) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the stub to return a Promise which resolves to the provided value. When constructing the Promise, sinon uses the Promise.resolve method. You are responsible for providing a polyfill in environments which do not provide Promise. Since sinon@2.0.0

                                                                                                        method resolvesArg

                                                                                                        resolvesArg: (index: number) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the stub to return a Promise which resolves to the argument at the provided index. stub.resolvesArg(0); causes the stub to return a Promise which resolves to the first argument. If the argument at the provided index is not available, a TypeError will be thrown.

                                                                                                        method resolvesThis

                                                                                                        resolvesThis: () => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the stub to return a Promise which resolves to its this value.

                                                                                                        method returns

                                                                                                        returns: (obj: TReturnValue) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Makes the stub return the provided

                                                                                                          Parameter obj

                                                                                                          value.

                                                                                                          Parameter obj

                                                                                                        method returnsArg

                                                                                                        returnsArg: (index: number) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the stub to return the argument at the provided

                                                                                                          Parameter

                                                                                                          index. stub.returnsArg(0); causes the stub to return the first argument. If the argument at the provided index is not available, prior to sinon@6.1.2, an undefined value will be returned; starting from sinon@6.1.2, a TypeError will be thrown.

                                                                                                          Parameter index

                                                                                                        method returnsThis

                                                                                                        returnsThis: () => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the stub to return its this value. Useful for stubbing jQuery-style fluent APIs.

                                                                                                        method set

                                                                                                        set: (func: (v: any) => void) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Defines a new setter for this stub.

                                                                                                          Parameter func

                                                                                                        method throws

                                                                                                        throws: {
                                                                                                        (type?: string): SinonStub<TArgs, TReturnValue>;
                                                                                                        (obj: any): SinonStub<TArgs, TReturnValue>;
                                                                                                        };
                                                                                                        • Causes the stub to throw an exception (Error).

                                                                                                          Parameter type

                                                                                                        • Causes the stub to throw the provided exception object.

                                                                                                        method throwsArg

                                                                                                        throwsArg: (index: number) => SinonStub<TArgs, TReturnValue>;
                                                                                                        • Causes the stub to throw the argument at the provided index. stub.throwsArg(0); causes the stub to throw the first argument as the exception. If the argument at the provided index is not available, a TypeError will be thrown. Since sinon@2.3.0

                                                                                                          Parameter index

                                                                                                        method throwsException

                                                                                                        throwsException: {
                                                                                                        (type?: string): SinonStub<TArgs, TReturnValue>;
                                                                                                        (obj: any): SinonStub<TArgs, TReturnValue>;
                                                                                                        };

                                                                                                          method value

                                                                                                          value: (val: any) => SinonStub<TArgs, TReturnValue>;
                                                                                                          • Defines a new value for this stub.

                                                                                                            Parameter val

                                                                                                          method withArgs

                                                                                                          withArgs: (
                                                                                                          ...args: MatchPartialArguments<TArgs>
                                                                                                          ) => SinonStub<TArgs, TReturnValue>;
                                                                                                          • Stubs the method only for the provided arguments. This is useful to be more expressive in your assertions, where you can access the spy with the same call. It is also useful to create a stub that can act differently in response to different arguments.

                                                                                                            Parameter args

                                                                                                          method yields

                                                                                                          yields: (...args: any[]) => SinonStub<TArgs, TReturnValue>;
                                                                                                          • Similar to callsArg. Causes the stub to call the first callback it receives with the provided arguments (if any). If a method accepts more than one callback, you need to use callsArg to have the stub invoke other callbacks than the first one.

                                                                                                          method yieldsAsync

                                                                                                          yieldsAsync: (...args: any[]) => SinonStub<TArgs, TReturnValue>;
                                                                                                          • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                            Parameter args

                                                                                                          method yieldsOn

                                                                                                          yieldsOn: (context: any, ...args: any[]) => SinonStub<TArgs, TReturnValue>;
                                                                                                          • Like above but with an additional parameter to pass the this context.

                                                                                                          method yieldsOnAsync

                                                                                                          yieldsOnAsync: (context: any, ...args: any[]) => SinonStub<TArgs, TReturnValue>;
                                                                                                          • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                            Parameter context

                                                                                                            Parameter args

                                                                                                          method yieldsRight

                                                                                                          yieldsRight: (...args: any[]) => SinonStub<TArgs, TReturnValue>;

                                                                                                            method yieldsTo

                                                                                                            yieldsTo: (property: string, ...args: any[]) => SinonStub<TArgs, TReturnValue>;
                                                                                                            • Causes the spy to invoke a callback passed as a property of an object to the spy. Like yields, yieldsTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.

                                                                                                              Parameter property

                                                                                                              Parameter args

                                                                                                            method yieldsToAsync

                                                                                                            yieldsToAsync: (
                                                                                                            property: string,
                                                                                                            ...args: any[]
                                                                                                            ) => SinonStub<TArgs, TReturnValue>;
                                                                                                            • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                              Parameter property

                                                                                                              Parameter args

                                                                                                            method yieldsToOn

                                                                                                            yieldsToOn: (
                                                                                                            property: string,
                                                                                                            context: any,
                                                                                                            ...args: any[]
                                                                                                            ) => SinonStub<TArgs, TReturnValue>;
                                                                                                            • Like above but with an additional parameter to pass the this context.

                                                                                                            method yieldsToOnAsync

                                                                                                            yieldsToOnAsync: (
                                                                                                            property: string,
                                                                                                            context: any,
                                                                                                            ...args: any[]
                                                                                                            ) => SinonStub<TArgs, TReturnValue>;
                                                                                                            • Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).

                                                                                                              Parameter property

                                                                                                              Parameter context

                                                                                                              Parameter args

                                                                                                            interface SinonStubStatic

                                                                                                            interface SinonStubStatic {}

                                                                                                              call signature

                                                                                                              <TArgs extends readonly any[] = any[], R = any>(): SinonStub<TArgs, R>;
                                                                                                              • Creates an anonymous stub function

                                                                                                              call signature

                                                                                                              <T>(obj: T): SinonStubbedInstance<T>;
                                                                                                              • Stubs all the object’s methods. Note that it’s usually better practice to stub individual methods, particularly on objects that you don’t understand or control all the methods for (e.g. library dependencies). Stubbing individual methods tests intent more precisely and is less susceptible to unexpected behavior as the object’s code evolves. If you want to create a stub object of MyConstructor, but don’t want the constructor to be invoked, use this utility function.

                                                                                                              call signature

                                                                                                              <T, K extends keyof T>(obj: T, method: K): SinonStubbedFunction<T[K]>;
                                                                                                              • Replaces obj.method with a stub function. An exception is thrown if the property is not already a function. The original function can be restored by calling object.method.restore(); (or stub.restore();).

                                                                                                              Type Aliases

                                                                                                              type DeepPartialOrMatcher

                                                                                                              type DeepPartialOrMatcher<T> = MatchPartialArguments<T>;

                                                                                                                type MatchArguments

                                                                                                                type MatchArguments<T> = MatchExactArguments<T>;

                                                                                                                  type MatchExactArguments

                                                                                                                  type MatchExactArguments<T> = {
                                                                                                                  [K in keyof T]:
                                                                                                                  | SinonMatcher
                                                                                                                  | (T[K] extends object ? MatchExactArguments<T[K]> : T[K]);
                                                                                                                  };

                                                                                                                    type MatchPartialArguments

                                                                                                                    type MatchPartialArguments<T> = {
                                                                                                                    [K in keyof T]?:
                                                                                                                    | SinonMatcher
                                                                                                                    | (T[K] extends object ? MatchPartialArguments<T[K]> : T[K]);
                                                                                                                    };

                                                                                                                      type SinonFakeTimers

                                                                                                                      type SinonFakeTimers = FakeTimers.Clock & {
                                                                                                                      /**
                                                                                                                      * Restores the original clock
                                                                                                                      * Identical to uninstall()
                                                                                                                      */
                                                                                                                      restore(): void;
                                                                                                                      };

                                                                                                                        type SinonPromise

                                                                                                                        type SinonPromise<T> = Promise<T> & {
                                                                                                                        status: 'pending' | 'resolved' | 'rejected';
                                                                                                                        resolve(val: unknown): Promise<T>;
                                                                                                                        reject(reason: unknown): Promise<void>;
                                                                                                                        resolvedValue?: T;
                                                                                                                        rejectedValue?: unknown;
                                                                                                                        };

                                                                                                                          type SinonSpiedInstance

                                                                                                                          type SinonSpiedInstance<T> = {
                                                                                                                          [P in keyof T]: SinonSpiedMember<T[P]>;
                                                                                                                          };

                                                                                                                            type SinonSpiedMember

                                                                                                                            type SinonSpiedMember<T> = T extends (...args: infer TArgs) => infer TReturnValue
                                                                                                                            ? SinonSpy<TArgs, TReturnValue>
                                                                                                                            : T;

                                                                                                                              type SinonStatic

                                                                                                                              type SinonStatic = SinonSandbox & SinonApi;

                                                                                                                                type SinonStubbedFunction

                                                                                                                                type SinonStubbedFunction<T> = T extends (...args: infer TArgs) => infer TReturnValue
                                                                                                                                ? SinonStub<TArgs, TReturnValue>
                                                                                                                                : SinonStub;
                                                                                                                                • Replaces a function type with a Sinon stub.

                                                                                                                                type SinonStubbedInstance

                                                                                                                                type SinonStubbedInstance<TType> = TType & {
                                                                                                                                [P in keyof TType]: SinonStubbedMember<TType[P]>;
                                                                                                                                };
                                                                                                                                • An instance of a stubbed object type with functions replaced by stubs.

                                                                                                                                  TType Object type being stubbed.

                                                                                                                                type SinonStubbedMember

                                                                                                                                type SinonStubbedMember<T> = T extends (...args: infer TArgs) => infer TReturnValue
                                                                                                                                ? SinonStub<TArgs, TReturnValue>
                                                                                                                                : T;
                                                                                                                                • Replaces a type with a Sinon stub if it's a function.

                                                                                                                                type StubbableType

                                                                                                                                type StubbableType<TType> = Function & { prototype: TType };
                                                                                                                                • Stubbed type of an object with members replaced by stubs.

                                                                                                                                  TType Type being stubbed.

                                                                                                                                Package Files (1)

                                                                                                                                Dependencies (1)

                                                                                                                                Dev Dependencies (0)

                                                                                                                                No dev dependencies.

                                                                                                                                Peer Dependencies (0)

                                                                                                                                No peer dependencies.

                                                                                                                                Badge

                                                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/sinon.

                                                                                                                                • Markdown
                                                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/sinon)
                                                                                                                                • HTML
                                                                                                                                  <a href="https://www.jsdocs.io/package/@types/sinon"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>