Tuesday 17 October 2017

[help] Patterns for using Async/Await with Mocha

I'm currently looking for suggestions on patterns for how to best handle writing async/await tests within Mocha. In writing tests that handle an unresolved or rejected promises, I'm getting the following warning message.(node:81841) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.With the code being:it('should return a 401 if the auth token is missing or invalid', async () => { let result; let error; const seed = await agent.post('/workOrder/').set('Authorization', authHeader).send(workOrder); const id = seed.body.id; try { result = await agent.get(`/workOrder/${id}`); } catch (e) { error = e; } expect(result).to.be.undefined; expect(error).to.not.be.undefined; expect(error.response.text).to.equal('Cannot Authenticate'); expect(error.response.status).to.equal(401); }); I know that Mocha does not like the use of Lambdas, but have not seen any negative effects in using them so far.Basically looking for any insights or resources on how to handle this.

Submitted October 17, 2017 at 04:27PM by AtWorkBeCool

No comments:

Post a Comment