Last active
July 5, 2016 11:15
-
-
Save sroccaserra/1c2ab010e3ba37f22973 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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