avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

t.throwsAsync is not a function #2203

Closed Oloompa closed 5 years ago

Oloompa commented 5 years ago

Description

V2.2.0 examples are not working for throwsAsync: https://github.com/avajs/ava/blob/v2.2.0/docs/03-assertions.md#throwsasyncthrower-expected-message

TypeError {
    message: 't.throwsAsync is not a function',
  }

Test Source

import test, { TestInterface } from "ava";

test("throws", async t => {
    await t.throwsAsync(
        async () => {
            throw new TypeError("🦄");
        },
        { instanceOf: TypeError, message: "🦄" }
    );
});
const promise = Promise.reject(new TypeError("🦄"));

test("rejects", async t => {
    const error = await t.throwsAsync(promise);
    t.is(error.message, "🦄");
});

Error Message & Stack Trace

failing_test.ts › throws

  /home/anthony/dev/artlighthouse/back-end/data/confirmation-code/test/failing_test.spec.ts:4

   3: test("throws", async t => {
   4:     await t.throwsAsync(   
   5:         async () => {      

  Rejected promise returned by test. Reason:

  TypeError {
    message: 't.throwsAsync is not a function',
  }

  failing_test.ts › rejects

  /home/anthony/dev/artlighthouse/back-end/data/confirmation-code/test/failing_test.spec.ts:14

   13: test("rejects", async t => {                   
   14:     const error = await t.throwsAsync(promise);
   15:     t.is(error.message, "🦄");                 

  Rejected promise returned by test. Reason:

  TypeError {
    message: 't.throwsAsync is not a function',
  }

  Unhandled Rejection
  TypeError: 🦄
Object.<anonymous> (test/failing_test.spec.ts:11:32)
Module.replacementCompile (node_modules/append-transform/index.js:58:13)
Module.m._compile (node_modules/ts-node/src/index.ts:473:23)
module.exports (node_modules/default-require-extensions/js.js:7:9)
node_modules/append-transform/index.js:62:4
require.extensions.(anonymous function) (node_modules/ts-node/src/index.ts:476:12)
node_modules/append-transform/index.js:62:4
Object.<anonymous> (node_modules/append-transform/index.js:62:4)

Command-Line Arguments

npx nyc ava-ts test/**/*.spec.ts

Environment

Node.js v10.15.2 linux 4.19.0-5-amd64 ava 2.2.0 npm 6.9.0

Oloompa commented 5 years ago

humpf, sorry it was due to ava-ts which is no longer needed to compile ts on the fly

solved

tylerlindell commented 4 years ago

humpf, sorry it was due to ava-ts which is no longer needed to compile ts on the fly

solved

What did you change to fix this?