مرجع سريع

ورقة غش مكتبة Sinon-Chai

دليل مرجعي سريع لمكتبة sinon-chai: دمج توكيدات Sinon.js مع أسلوبي expect و should في مكتبة Chai.

· تاريخ النشر

تربط مكتبة sinon-chai بين إمكانيات المراقبة والتزييف في Sinon.js مع صياغات التوكيد التعبيرية expect و should في Chai.

التثبيت والتهيئة

var sinon = require('sinon')
require('chai').use(require('sinon-chai'))

توكيدات بأسلوب Expect (Expect Style)

expect(spy).called
expect(spy).calledOnce
expect(spy).calledTwice
expect(spy).calledThrice
expect(spy).calledBefore(otherSpy)
expect(spy).calledAfter(otherSpy)
expect(spy).calledWithNew
expect(spy).alwaysCalledWithNew
expect(spy).calledOn(context)
expect(spy).alwaysCalledOn(context)
expect(spy).calledWith(...args)
expect(spy).alwaysCalledWith(...args)
expect(spy).calledWithExactly(...args)
expect(spy).alwaysCalledWithExactly(...args)
expect(spy).calledWithMatch(matcher)
expect(spy).alwaysCalledWithMatch(matcher)
expect(spy).returned(returnValue)
expect(spy).alwaysReturned(returnValue)
expect(spy).threw(errorOrType)
expect(spy).alwaysThrew(errorOrType)

توكيدات بأسلوب Should (Should Style)

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.have.been.calledWithExactly(...args)
spy.should.always.have.been.calledWithExactly(...args)
spy.should.have.been.calledWithMatch(matcher)
spy.should.always.have.been.calledWithMatch(matcher)
spy.should.have.returned(returnVal)
spy.should.have.always.returned(returnVal)
spy.should.have.thrown(errorObjOrString)
spy.should.have.always.thrown(errorObjOrString)

مراجع مفيدة

موضوعات ذات صلة