Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • SinonAssert

Index

Properties

failException

failException: string

Defaults to AssertError.

Methods

alwaysCalledOn

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

    Parameters

    Returns void

alwaysCalledWith

  • Passes if spy was always called with the provided arguments.

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

alwaysCalledWithExactly

  • Passes if spy was always called with the provided arguments and no others.

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

alwaysCalledWithMatch

  • 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), ...).

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

alwaysThrew

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

    Parameters

    Returns void

  • Like threw, only required for all calls to the spy.

    Parameters

    • spy: SinonSpy<any, any>
    • exception: string

    Returns void

  • Like threw, only required for all calls to the spy.

    Parameters

    • spy: SinonSpy<any, any>
    • exception: any

    Returns void

callCount

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

    Parameters

    Returns void

callOrder

  • callOrder(...spies: SinonSpy<any, any>[]): void
  • Passes if provided spies were called in the specified order.

    Parameters

    Returns void

called

  • Passes if spy was called at least once.

    Parameters

    Returns void

calledOn

  • 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, ...);.

    Parameters

    Returns void

calledOnce

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

    Parameters

    Returns void

calledOnceWithExactly

  • Passes if spy was called at exactly once with the provided arguments and no others.

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

calledOnceWithMatch

  • calledOnceWithMatch<TArgs>(spyOrSpyCall: SinonSpy<TArgs, any> | SinonSpyCall<TArgs, any>, ...args: 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, ...).

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

calledThrice

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

    Parameters

    Returns void

calledTwice

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

    Parameters

    Returns void

calledWith

  • 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, ...);.

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

calledWithExactly

  • 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, ...);.

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

calledWithMatch

  • 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, ...);.

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

calledWithNew

  • 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, ...);.

    Parameters

    Returns void

expose

  • 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

    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.

    Parameters

    Returns void

fail

  • fail(message?: string): void
  • Every assertion fails by calling this method. By default it throws an error of type sinon.assert.failException. If the test framework looks for assertion errors by checking for a specific exception, you can simply override the kind of exception thrown. If that does not fit with your testing framework of choice, override the fail method to do the right thing.

    Parameters

    • Optional message: string

    Returns void

match

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

    Parameters

    • actual: any
    • expected: any

    Returns void

neverCalledWith

  • Passes if spy was never called with the provided arguments.

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

neverCalledWithMatch

  • 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), ...).

    Type parameters

    • TArgs: any[]

    Parameters

    Returns void

notCalled

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

    Parameters

    Returns void

pass

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

    Parameters

    • assertion: any

    Returns void

threw

  • Passes if spy threw any exception.

    Parameters

    Returns void

  • 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);.

    Parameters

    Returns void

  • 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);.

    Parameters

    Returns void