import { test, expect, spyOn } from "bun:test";
import express from "express";
import request from "supertest";
import * as funcs from "./functions";
const app = express();
app.get("/", async (req, res) => {
try {
const text = await funcs.testFunc();
res.status(200);
return res.send(text);
} catch (err) {
res.status(400);
return res.send("Error");
}
});
test("supertest", async () => {
spyOn(funcs, "testFunc").mockRejectedValueOnce(new Error("error"));
const res = await request(app).get("/").expect(400);
expect(res.text).toBe("Error");
});
What is the expected behavior?
The test should pass as the function being called inside of the endpoint is being mocked to reject, and the Express route inside of the catch block sets the res.status to 400 and returns "Error".
What do you see instead?
The test hangs and the process doesn't complete:
Additional information
This style of tests works using Jest, I have been trying to convert an existing repo from Jest to bun test. if I change the spyOn to mock a different resolved value, the tests do not hang which makes me think it's related to the error being mocked or handling of errors.
What version of Bun is running?
1.1.4+fbe2fe0c3
What platform is your computer?
Darwin 23.4.0 arm64 arm
What steps can reproduce the bug?
When using an Express app and trying to test it with supertest, bun test hangs if a function within the tested express route is mocked to error:
What is the expected behavior?
The test should pass as the function being called inside of the endpoint is being mocked to reject, and the Express route inside of the catch block sets the res.status to 400 and returns "Error".
What do you see instead?
The test hangs and the process doesn't complete:
Additional information
This style of tests works using Jest, I have been trying to convert an existing repo from Jest to bun test. if I change the spyOn to mock a different resolved value, the tests do not hang which makes me think it's related to the error being mocked or handling of errors.