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

Feature request: accept async functions in beforeEach/afterEach #1542

Closed
ide opened this issue Aug 31, 2016 · 9 comments
Closed

Feature request: accept async functions in beforeEach/afterEach #1542

ide opened this issue Aug 31, 2016 · 9 comments

Comments

@ide
Copy link
Contributor

ide commented Aug 31, 2016

I'm using Aphrodite with React and Aphrodite asynchronously runs document.querySelector("style[data-aphrodite]") (scheduled with asap, so it uses process.nextTick). Jest seems to clean up the jsdom environment after each test so this results in an error because the tick callback runs after document has been set to undefined.

So what I want to do is this:

it('renders snapshot', () => {
  // Render a React component
});

afterEach(() => new Promise(resolve => process.nextTick(resolve)));

That way each test flushes all tick callbacks and allows Aphrodite to run.

@cpojer
Copy link
Member

cpojer commented Aug 31, 2016

duplicate of #1256.

This should be easy to implement: just overwrite beforeEach/afterEach the same way we overwrite it with jasmine-pit.

@cpojer cpojer closed this as completed Aug 31, 2016
@cpojer
Copy link
Member

cpojer commented Aug 31, 2016

please send a PR ;)

@ide
Copy link
Contributor Author

ide commented Aug 31, 2016

I'll venmo/messenger 5 bucks to whomever does a good job :)

In the meantime I'm using fake timers and

  afterEach(() => {
    jest.runAllTicks();
  });

@cpojer
Copy link
Member

cpojer commented Aug 31, 2016

afterEach already accepts done for async work, no?

@aaronabramov
Copy link
Contributor

it does. http://jasmine.github.io/2.5/introduction.html#section-55
i had no idea jest doesn't support it. I can work on it this week

@ide
Copy link
Contributor Author

ide commented Sep 6, 2016

This is already fixed in #1546 / 15.1.0.

@cpojer
Copy link
Member

cpojer commented Sep 6, 2016

@DmitriiAbramov @ide ended up doing this himself, therefore paying 5 bucks to himself.

@aaronabramov
Copy link
Contributor

oh. nevermind then.. still going through my jest emails from last week :)
thanks @ide for doing this!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants