How to import "describe" and "it" from mocha in TypeScript?

Ace picture Ace · Oct 2, 2016 · Viewed 22.4k times · Source

By default, when importing mocha in TypeScript, it brings in describe and it (and some others) into the global namespace.

Is there a way to bring in specific imports like import {describe, it} from 'mocha'?

Answer

Eryk Warren picture Eryk Warren · Dec 30, 2016

Install mocha and its types:

npm install mocha --save-dev
npm install @types/mocha --save-dev

Then, simply import mocha in your test files:

import 'mocha';

describe('my test', () => {
  it('does something', () => {
    // your test
  });
});