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.
const fn = sinon.stub();
fn.resolves('foo');
fn.then((actual) => actual.should.equal('foo'));
const fn = sinon.stub();
fn.rejects(new Error('bar'));
fn.catch((e) => e.message.should.equal('bar'));
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'));
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');
});
});
- 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