Skip to content

Instantly share code, notes, and snippets.

@kianaditya
Created July 8, 2020 13:10
Show Gist options
  • Save kianaditya/cb8bf55c7b43e6a2a116462c2c87625c to your computer and use it in GitHub Desktop.
Save kianaditya/cb8bf55c7b43e6a2a116462c2c87625c to your computer and use it in GitHub Desktop.
const sinon = require('sinon')
const expect = require('chai').expect
const queries = require('../../../src/models/queries')
const { show } = require('../../../src/controllers/users')
describe('Users Controller', () => {
const user = {}
describe('GET User', () => {
it('should use show action and send response', async () => {
const getUserStub = sinon.stub(queries, 'getUser').resolves(user)
let resSpy = sinon.spy()
const req = {
user: {
email: '[email protected]',
},
}
const res = {
status: sinon.stub().returns({ send: resSpy }),
}
await show(req, res)
expect(getUserStub.calledOnce).to.equal(true)
expect(resSpy.calledOnce).to.equal(true)
expect(resSpy.calledWith(user)).to.equal(true)
getUserStub.restore()
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment