UNPKG

node-express-mongodb-jwt-rest-api-skeleton

Version:

Node.js express.js MongoDB JWT REST API - This is a basic API REST skeleton written on JavaScript using async/await. Great for building a starter web API for your front-end (Android, iOS, Vue, react, angular, or anything that can consume an API)

39 lines (29 loc) 818 B
const { handleError } = require('./handleError') const mockResponse = () => { const res = {} res.status = jest.fn().mockReturnValueOnce(res) res.json = jest.fn().mockReturnValueOnce(res) return res } const err = { message: 'error', code: 123 } describe('handleError()', () => { it('should send the error object with the code and message provided and print the error code, message in development mode', async () => { process.env.NODE_ENV = 'development' const res = mockResponse() console.log = jest.fn() await handleError(res, err) expect(console.log).toHaveBeenCalledWith({ code: 123, message: 'error' }) expect(res.status).toHaveBeenCalledWith(123) expect(res.json).toHaveBeenCalledWith({ errors: { msg: 'error' } }) }) })