Skip to content

Instantly share code, notes, and snippets.

@nkhil
Created November 13, 2019 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkhil/7d7c89776b3eb297708a3f7dc3e2f456 to your computer and use it in GitHub Desktop.
Save nkhil/7d7c89776b3eb297708a3f7dc3e2f456 to your computer and use it in GitHub Desktop.
// file: controller.spec.js
const proxyquire = require('proxyquire');
const sinon = require('sinon');
const chai = require('chai');
const { expect } = chai;
describe('calculateTotal', function(done) {
it('calculates the total and updates the database', function() {
const databaseUpdaterSpy = sinon.spy();
const stub = {
'../model/databaseUpdater': databaseUpdaterSpy,
};
const calculateTotal = proxyquire('../controller', stub);
calculateTotal([2, 3, 5]);
expect(databaseUpdaterSpy.getCall(0).calledWith(sinon.match({ body: 10 }))).to.be.true;
done();
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment