Skip to content

Instantly share code, notes, and snippets.

@adover
Last active May 8, 2018 23:43
Show Gist options
  • Save adover/b2bb22ae085a6ebcc23ff53fe5402258 to your computer and use it in GitHub Desktop.
Save adover/b2bb22ae085a6ebcc23ff53fe5402258 to your computer and use it in GitHub Desktop.
const sinon = require('sinon');
const chai = require('chai');
const expect = chai.expect;
const SomeController = require('../../app/controllers/SomeController')
describe('SomeController', () => {
let stub;
beforeEach(() => {
stub = sinon.stub(SomeController, 'doAPICall');
});
describe('addLeave', () => {
it('Should be a function', () => {
expect(SomeController.addLeave).to.be.a('function');
});
it('Should return false if no employeeID', async () => {
const result = await BambooController.addLeave();
expect(result).to.be.false;
});
it('Should return an array of objects', async () => {
stub.resolves('10');
const result = await SomeController.addLeave('5');
expect(result).to.equal('success');
});
it('Should return false after being rejected', async () => {
stub.rejects();
const result = await SomeController.addLeave('5');
expect(result).to.throw();
});
});
afterEach(() => {
stub.restore();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment