Skip to content

Instantly share code, notes, and snippets.

@sroccaserra
Last active July 5, 2016 11:15
Show Gist options
  • Select an option

  • Save sroccaserra/1c2ab010e3ba37f22973 to your computer and use it in GitHub Desktop.

Select an option

Save sroccaserra/1c2ab010e3ba37f22973 to your computer and use it in GitHub Desktop.
const boom = require('boom')
const productProvider = require('./services/product-provider')
function getProducts(request, reply) {
productProvider.findAll((err, products) => {
if (err) {
return reply(boom.internal("Something happened!", err))
}
reply(products)
}
}
module.exports = {
getProducts: getProducts
}
const productProvider = require('../../services/product_v1/provider-mongo')
const productController = require('../../services/product_v1/controllers') // <-- SUT
describe('productController', function() {
afterEach(function() {
// Why: we must absolutely restore the stubbed function here, in order not to disturb other tests.
productProvider.findAll.restore()
})
it('should stub a provider function.', function() {
// Given
sinon.stub(productProvider, 'findAll').yields(null, aProduct())
// When
productController.getProductList(stubRequest(), result => {
// Then
assert.deepEqual(aProduct(), result)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment