ts-node and mocha ‘TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension “.ts”‘ error even with “ts-node/esm” loader and CommonJS modules

i’m using same configuration like yours but it only work when i downgrade to ts-node@9, and then i tried this option in my .mocharc.json and now it’s working as i expected { “extensions”: [“ts”], “spec”: [“**/*.spec.*”], “node-option”: [ “experimental-specifier-resolution=node”, “loader=ts-node/esm” ] }

Post request via Chai

The way you have written, I assume that you used chai-http package. The .field() function does not work in chai-http. Another user pointed it out here and opened an issue on github. Here is how you could have written: .set(‘content-type’, ‘application/x-www-form-urlencoded’) .send({myparam: ‘test’}) Here is the full code that successfully passes parameters to the server: … Read more

Testing asynchronous function with mocha

You have to specify the callback done as the argument to the function which is provided to mocha – in this case the it() function. Like so: describe(‘api’, function() { it(‘should load a user’, function(done) { // added “done” as parameter assert.doesNotThrow(function() { doRequest(options, function(res) { assert.equal(res, ‘{Object … }’); // will not fail assert.doesNotThrow … Read more

What does ‘pending’ test mean in Mocha, and how can I make it pass/fail?

A test can end up being shown by Mocha as “pending” when you inadvertently closed the test’s it method early, like: // Incorrect — arguments of the it method are closed early it(‘tests some functionality’), () => { // Test code goes here… }; The it method’s arguments should include the test function definition, like: … Read more

Mocha’s describe “require() is missing” in WebStorm 11

Edit: As noted in the comments, the actual issue addressed in this question is actually a bug in IntelliJ 15 / WebStorm 11 (see https://youtrack.jetbrains.com/issue/WEB-18768). I’m leaving the answer below because many people come here when searching for the solution provided. 2023 edit: Looking back at this, I think that if you include the @types/mocha … Read more

tech