Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

casumo-archive/more-sinon-chai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

More Sinon Chai

Extra functionality for sinon and chai.

At some point we should probably move functionality here to relevant community projects. In the meantime we need a place for this.

API

stub.resolves()

const fn = sinon.stub();

fn.resolves('foo');

fn.then((actual) => actual.should.equal('foo'));

stub.rejects()

const fn = sinon.stub();

fn.rejects(new Error('bar'));

fn.catch((e) => e.message.should.equal('bar'));

stub.promises()

Use this when the timing of the promise resolution matters, or when creating general, promise-returning test doubles.

const fn = sinon.stub();

fn.promises();

fn.promise === fn();
const fn = sinon.stub().promises();

fn.resolvePromise('foo');

fn.then((actual) => actual.should.equal('foo'));
const fn = sinon.stub().promises();

fn.rejectPromise(new Error('bar'));

fn.catch((e) => e.message.should.equal('bar'));

chai.should.eventuallyBeCalled()

Use this for testing that a callback is eventually called.

Note: Although this is more of a spy method, it can only be used on stubs due to the internals of chai.

it('should call stub after some time', () => {

    const fn = sinon.stub();

    window.setTimeout(() => {
        fn('foo', 'bar');
    }, 100);

    return fn.should.eventuallyBeCalled().then(([arg1, arg2]) => {
        arg1.should.equal('foo');
        arg2.should.equal('bar');
    });

});

Releasing an update

  • Update version in package.json to n.n.n
  • Push / merge your changes to master
  • git checkout -b release-n.n.n
  • yarn dist
  • git add -f dist
  • git commit -m "Release n.n.n"
  • git tag n.n.n
  • git push origin n.n.n
  • npm login
  • npm publish
  • Delete your local release branch at your leisure

About

Extra functionality for sinon and chai

Resources

Stars

Watchers

Forks

Packages

No packages published