Skip to content
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

t.throwsAsync fails when throwing Errors #2408

Closed
bunysae opened this issue Feb 22, 2020 · 1 comment
Closed

t.throwsAsync fails when throwing Errors #2408

bunysae opened this issue Feb 22, 2020 · 1 comment

Comments

@bunysae
Copy link
Contributor

bunysae commented Feb 22, 2020

Actual behavior
When i try to execute the following tests,

test('should throw error (sinon stub)', async t => {
        const error = new Error('a');
        const stub = require('sinon').stub();
        stub.throws(error);
        const afunc = async () => {
                return stub();
        };
        t.throwsAsync(await afunc());
});

async function error(){
        throw new Error('a');
}

test('should throw error', async t => {
        const afunc = async () => {
                return await error();
        };
        t.throwsAsync(await afunc())
});

i get the error

Rejected promise returned by test. Reason:

  Error {
    message: 'a',
  }

Expected behavior
The tests should pass.

Environment

  • AVA: 3.3.0
  • Node.js: v12.10.0
  • System: SuSe Linux
@novemberborn
Copy link
Member

t.throwsAsync(await afunc());

You're awaiting afunc() before throwsAsync() is called.

Change to:

await t.throwsAsync(afunc());

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

No branches or pull requests

2 participants