vendredi 18 décembre 2020

How do I configure mocha to print full stack trace for an error?

I run the following Test in Typescript with mocha:

Mocha command:

$ mocha -r ts-node/register -r test/config.ts --timeout 10000 --async-stack-traces --full-trace 'test/**/*.test.ts'

Test:

describe.only("My test", () => {

    it("should work properly", async () => {
        const response = await client.postArticle(testArticle);
            
        assert.strictEqual(response.status, StatusCodes.OK);
        // More test code
    });
});

The test fails already before the assertion, an error gets thrown inside the postArticle function. My problem is, that it does not tell me the line of code that caused the error:

Error: Request failed with status code 401
      at createError (/.../node_modules/axios/lib/core/createError.js:16:15)
      at settle (/.../node_modules/axios/lib/core/settle.js:17:12)
      at IncomingMessage.handleStreamEnd (/.../node_modules/axios/lib/adapters/http.js:244:11)
      at IncomingMessage.emit (node:events:341:22)
      at IncomingMessage.EventEmitter.emit (node:domain:467:12)
      at endReadableNT (node:internal/streams/readable:1294:12)
      at processTicksAndRejections (node:internal/process/task_queues:80:21)

Especially in more complex tests, it would be really helpful to know, which line of code caused the error. How can I configure mocha to display this line?

Aucun commentaire:

Enregistrer un commentaire