DEV Community

Lam
Lam

Posted on

4 2

Sinon-Chai Cheat Sheet

Should

    spy.should.have.been.called
    spy.should.have.been.calledOnce
    spy.should.have.been.calledTwice
    spy.should.have.been.calledThrice
    spy1.should.have.been.calledBefore(spy2)
    spy1.should.have.been.calledAfter(spy2)
    spy.should.have.been.calledWithNew
    spy.should.always.have.been.calledWithNew
    spy.should.have.been.calledOn(context)
    spy.should.always.have.been.calledOn(context)
    spy.should.have.been.calledWith(...args)
    spy.should.always.have.been.calledWith(...args)
    spy.should.always.have.been.calledWithExactly(...args)
    spy.should.always.have.been.calledWithExactly(...args)
    spy.should.have.been.calledWithMatch(...args)
    spy.should.always.have.been.calledWithMatch(...args)
    spy.should.have.returned(returnVal)
    spy.should.have.always.returned(returnVal)
    spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing)
    spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing)
Enter fullscreen mode Exit fullscreen mode

Assert

    expect(spy).called
    expect(spy).calledOnce
    expect(spy).calledTwice
    expect(spy).calledThrice
    expect(spy).calledBefore
    expect(spy).calledAfter
    expect(spy).calledWithNew
    expect(spy).alwaysCalledWithNew
    expect(spy).calledOn
    expect(spy).alwaysCalledOn
    expect(spy).calledWith
    expect(spy).alwaysCalledWith
    expect(spy).calledWithExactly
    expect(spy).alwaysCalledWithExactly
    expect(spy).calledWithMatch
    expect(spy).alwaysCalledWithMatch
    expect(spy).returned
    expect(spy).alwaysReturned
    expect(spy).threw
    expect(spy).alwaysThrew
Enter fullscreen mode Exit fullscreen mode

Initialization

var sinon = require('cs/sinon');
require('cs/chai').use(require('cs/sinon-chai'));
Enter fullscreen mode Exit fullscreen mode

Reference

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay