I am looking for IntelliJ, or a similar IDE like WebStorm or VSCode, to provide auto-complete for the fields I define in my Mocha.js before() hook within my test context. Furthermore, I want to have access to the auto-complete documentation of those fields in all of my unit tests that utilize that test context.
Let me illustrate with an example:
describe('🔥Awesome Test Code🔥', async function()
{
/** A super expensive thing that each unit test needs. **/
class ExpensiveThing { expensive = true; }
/**
* Execute this once before the first test in this describe block.
* {@link https://mochajs.org/#hooks Mocha Hooks}
* {@link https://mochajs.org/#global-teardown-fixtures Mocha Test Contexts}
*/
before('the first test', async function()
{
// We can prepare anything we want here and set it on this
// so that each unit test can access it when the unit test runs.
// This is better than initializing it in the describe() block
// because then the code would run when mocha parses the tests
// and it would get executed even if the test is not run.
// https://mochajs.org/#global-teardown-fixtures
this.expensiveThingUsedForTheTests = new ExpensiveThing();
//👆 ⬆️ ⬆️
// ________|__________________________________|________
// !!! I want to define the type of this field here !!!
// ----------------------------------------------------
});
it('should be easy', async function(){
this.expensiveThingUsedForTheTests.expensive = false;
//👆 ⬆️ ⬆️
// ________|___________________________|_________________________
// !!! I want this to give me auto-complete and documentation !!!
// --------------------------------------------------------------
assert.equal(this.expensiveThingUsedForTheTests.expensive, false, 'This was not easy!');
});
});
However, when I press CTRL+Q on the field in IntelliJ IDEA, this is what I see instead: https://i.sstatic.net/DdXvpKm4.png