Jest async example needs an await https://basarat.gitbook.io/typescript/intro-1/jest

Author: AnupamKhoslaCreated Jul 6, 2025Updated Jul 6, 2025

https://basarat.gitbook.io/typescript/intro-1/jest

Following is wrong:

test('basic',async () => {
  expect(sum()).toBe(0);
});

test('basic again', async () => {
  expect(sum(1, 2)).toBe(3);
}, 1000 /* optional timeout */);

You need await like:

test('basic', async () => {
    expect(await sum()).toBe(0);
});