microsoft / TypeScript-Node-Starter

A reference example for TypeScript and Node with a detailed README describing how to use the two together.
MIT License
11.31k stars 2.77k forks source link

async/await Jest tests #175

Open kpelelis opened 5 years ago

kpelelis commented 5 years ago

Hey everyone! This project has been a great help so far. I have been experimenting with tests a little bit and I couldn't get async tests to pass the compilation. I have something along the lines of:

describe("Model Test", () => {
  beforeAll(async (done) => {
    // Do stuff
  });

And I get the following error:

TS2705: An async function or method in ES5/ES3 requires the Promise constructor. Make sure you have a declaration for the Promise constructor or include ES2015 in your --lib option.

And for completeness, my tsconfig looks something like this:

{
  "compilerOptions": {
    "module": "commonjs",
    "esModuleInterop": true,
    "target": "es6",
    "noImplicitAny": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "sourceMap": true,
    "outDir": "dist",
    "baseUrl": ".",
    "lib": ["es2017"],
    "paths": {
      "*": [
        "node_modules/*",
        "src/types/*"
      ]
    }
  },
  "include": [
    "src/**/*",
    "config/**/*.ts",
    "index.ts"
  ]
}

So I guess the "es2017" setting in the "lib" parameter does not really have any effect.