-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Asynchronous beforeEach / beforeAll? #1256
Comments
Also filed an issue in jest. jasmine/jasmine#1145 |
I don't believe that If you'd like to send a pull request (with an integration test! See |
Will definitely take a look. In the meantime this is my work around. Tested working empirically with jest 1.3.1 :) Just need to use the beforeAll(async (done) => {
const accessToken = await api.getAccessToken()
// Do whatever you need to do
done()
}) |
Can we reopen this one as beforeAll, afterAll was not addressed? |
@dyst5422 it's working for me no. |
All lifecycle functions accepts promises, yes: https://github.com/facebook/jest/blob/aef82a2a8ae9b249c40bcd558552bfb11ca43894/packages/jest-jasmine2/src/jasmine_async.js#L124-L127 |
Yeah, I realized this later today. My issue was in trying to asyncronously control which tests ran. So i was doing it.skipIf(() => Promise, 'mytest', () => Promise), which clearly won't work because jest collects all tests syncronously. |
You can track #5673. Not sure if it covers your use case, though |
Why do we need to call |
@CMCDragonkai if you use async/await/promises you don't need to call |
I tested it here:
The above works, but if I remove the Oh I just tested again without the done parameter. It ends up working awesome! |
The "accepted" comment makes no sense, jest shouldn't be analyzing function innards to see if |
Same issue, any solution? |
@VitorBrangioni To ensure lifecycle hooks execution order I am using "module": "commonJS" (tsconfig.json). |
Just experienced it. It looks like a bug. I workarounded it by setting custom high timeout value. Edit: Actually it skips other errors as well. |
I'm getting something similar, errors from async ops are getting ignored, the only way to get them is by using try/catch. beforeEach(async () => {
await getConnection().synchronize(true); // throws error
log('done'); // this isn't printed
}); |
Same as @devniel said here, Even using the |
This issue is closed. Any bugs with the current release of Jest (v26 at the time of writing) should be reported in new issues with reproductions. In general though, using both a |
I don't know where is the catch but using an async and / or using the callback NOT prevents other in short: this simplified code can fail (variable is undefined) let variable;
beforeAll(async (done) => {
variable = await initVariable();
done();
});
it('should do something', async () => {
expect(variable).toBeDefined();
} this "can" fail as well (variable is undefined) let variable;
beforeAll(async () => {
variable = await initVariable();
});
it('should do something', async () => {
expect(variable).toBeDefined();
} |
@Xample I thought I had the same problem but it turned out that I did not set the enough timeout for |
@Xample I have the same issue, using |
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. |
Is it supported by jest? Sometimes test setup methods do not run synchronously.
The text was updated successfully, but these errors were encountered: