© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2023
D. IrvineBuild Your Own Test Frameworkhttps://doi.org/10.1007/978-1-4842-9247-1_9

9. Supporting Asynchronous Tests

Daniel Irvine1  
(1)
London, UK
 
Sometimes we want to test async stuff:
it("does something async", async () => {
  await something();
  expect(thing).toBe("foo");
});

For this to work, notice that the second argument to the it function call is now marked as async. This is a hint to how the test runner must change: it must assume that the test body returns a Promise object, which is what the async method means.

But with our current test runner, our tests will complete, reporting no failures for any test that awaits a Promise, because our test runner won’t ...

Get Build Your Own Test Framework: A Practical Guide to Writing Better Automated Tests now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.