Skip to content

When using an async function in t.throws(), receive errors: "Function returned: Promise {}" and "Unhandled rejection" #1931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lukenickerson opened this issue Sep 7, 2018 · 1 comment

Comments

@Lukenickerson
Copy link

Description

In 1.0.0-beta.8 (with no special configuration or command line arguments) I'm seeing an error with essentially the same function that was posted in #1371.

Test Source

import test from 'ava';

test('test', async (t) => {
  await t.throws(async () => {
    throw new Error();
  });
});

Error Message & Stack Trace

Message returned from running the test says something like:

1 test failed
1 unhandled rejection

Line: await t.throws(async () => {
Function returned: Promise {}

Line: throw new Error();
Unhandled rejection in [test filename]

Environment

Node.js v10.9.0
darwin 17.6.0
AVA 1.0.0-beta.8
npm 6.2.0

@novemberborn
Copy link
Member

Ah sorry about that. As of Beta 7, t.throws() only works for synchronous errors. You'll need to change your test to use t.throwsAsync().

However we should provide better feedback in the test output. I've opened #1932 with some pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants