Skip to content

await t.throws is not waiting #391

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
SamVerschueren opened this issue Dec 30, 2015 · 4 comments
Closed

await t.throws is not waiting #391

SamVerschueren opened this issue Dec 30, 2015 · 4 comments

Comments

@SamVerschueren
Copy link
Contributor

Hi

The latest tests of the delay module are not working as you can see in this travis report.

I investigated it and I noticed some weird stuff was going on with the x.throws method.

test('returns a rejected promise', async t => {
    console.log('start');
    await t.throws(fn.reject(50, new Error('foo')), 'foo');
    console.log('done');
});

I added an extra log in the setTimeout method of the delay module. This is the output:

start
done
setTimeout

Does anyone has an idea how this is possible? I will try to add a failing test with the delay module.

@SamVerschueren
Copy link
Contributor Author

It's actually hard, or maybe impossible, to write a failing test for this as it might be Babel related.

So here is a small code snippet

import test from 'ava';

function delay() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            reject(new Error('foo'));
        }, 500);
    });
}

test('await', async t => {
    const start = Date.now();
    await t.throws(delay, 'foo');

    t.true(Date.now() - start > 500);
});

which results in

  1. await
  Missing expected exception..
  AssertionError: Missing expected exception..

@sindresorhus
Copy link
Member

Probably related to #360. You no longer need to await t.throws.

@SamVerschueren
Copy link
Contributor Author

That indeed solves the issue in my first post. Refactored the tests and now they are working correctly. My second post actually looks like another issue. Closing this one and will create a new issue. Have to investigate first.

@SamVerschueren
Copy link
Contributor Author

The code snippet of my second post is wrong, that's why it wasn't working. It had to be t.throws(delay(), 'foo').

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