Reputation: 14848
I have some unit tests that all execute things asynchronously. But it turns out that even though I'm calling expectAsync a bunch of times in side my unit tests (sometimes this may involve multiple nested asynchronous calls to expectAsync), the unit tests still exits and calls the tearDown method which effectively is cutting off my infrastructure that my asynchronous tests are running on. What I want to happen is for my tests to run and wait until all the expectations, async or not, to have completed before it continues on to the next test. Is this possible to achieve? the reason my unit tests have been passing up to now is because the clean up code in tearDown was also executing async, but it should ideally work weather it cleans up asynchronously or immediately.
Upvotes: 0
Views: 313
Reputation: 71613
We need to see your code to be able to pinpoint the exact problem.
Most likely you are not calling expectAsync
enough. At any time your code is waiting for an asynchronous callback, there must be at least one outstanding expectAsync
function waiting to be called.
You can cut it all down to one expectAsync
call by creating a "done" function that you call whenever your test is completed:
test("ladadidadida", () {
var done = expectAsync((){});
something.then((a) { return somethingElse(); })
.then((b) { expect(a, b); done(); })
});
Upvotes: 3