forwardemail / forwardemail/supertest
Using async, tests in series fail after first test run.
- Dominant language
- JavaScript
- Stars
- 14.4k
- Forks
- 782
- PR merge metrics
- No merged PRs in 30d
Description
When defining a series of tests using async, the first test passes as expected but subsequent tests fail with 404.
```
describe("Test server ping", () => {
let app: express.Application;
beforeEach(() => {
app = getApp();
});
it("should return pong", async () => {
const res = await request(app).get("/ping");
expect(res.status).toBe(200);
});
it("should reset", async () => {
const res = await request(app).get("/reset");
expect(res.status).toBe(205);
});
});
```
```
FAIL test/integration/server/__tests__/pingpong.test.ts
Test server ping
✓ should return pong (106ms)
✕ should reset (27ms)
● Test server ping › should reset
expect(received).toBe(expected) // Object.is equality
Expected: 205
Received: 404
30 | const res = await request(app).get("/reset");
> 31 | expect(res.status).toBe(205);
| ^
32 | });
33 |
at Object. (test/integration/server/__tests__/pingpong.test.ts:31:28)
at step (test/integration/server/__tests__/pingpong.test.ts:32:23)
at Object.next (test/integration/server/__tests__/pingpong.test.ts:13:53)
at fulfilled (test/integration/server/__tests__/pingpong.test.ts:4:58)
```
The same test series will pass using classic supertest expect. E.g.
```
it("should reset", async () => {
request(app)
.get("/reset")
.expect(205);
});
```
Using jest with ts-node.
Contributor guide
Research direction
Run test/integration/server/__tests__/pingpong.test.ts with Jest and ts-node, starting with the async request cases and the classic supertest expect comparison shown in the report. Trace why the first request succeeds while the later /reset request returns 404, then verify that the async test series produces the expected 200 and 205 responses.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- express, node.js, typescript
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100