Closed dels07 closed 4 years ago
Hi,
I have auth.handler middleware that call some async function that I having problem to test using mocha & chai, using done() not helping either here, example code:
done()
middleware
async function authHandler(req, res, next) { const token = req.headers.authorization.split(' ')[1] const validCredential = await AuthService.verifyAccess(token) if (!validCredential) { next(new Error('Invalid credential') } next() }
test
it('should return error', async () => { const token = 'invalid-token' const { req, res} = mockSetup(token) await authHandler(req, res, function next(error) => { expect(res.status).to.be.equal(500) expect(error.message).to.be.equal('invalid credential') }) })
Stale issue message
@dels07 was your problem that the test was hanging? If so, I'm facing the same issue now - did you manage to resovle it?
Hi,
I have auth.handler middleware that call some async function that I having problem to test using mocha & chai, using
done()
not helping either here, example code:middleware
test