aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/node-test-helpers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/bun.js/node-test-helpers.ts')
-rw-r--r--test/bun.js/node-test-helpers.ts21
1 files changed, 15 insertions, 6 deletions
diff --git a/test/bun.js/node-test-helpers.ts b/test/bun.js/node-test-helpers.ts
index 34147c194..0eaa7d07b 100644
--- a/test/bun.js/node-test-helpers.ts
+++ b/test/bun.js/node-test-helpers.ts
@@ -123,13 +123,22 @@ export const createCallCheckCtx = (done: DoneCb) => {
// mustCallChecks.push(context);
const done = createDone();
const _return = (...args) => {
- // @ts-ignore
- const result = fn.apply(this, args);
- actual++;
- if (actual >= expected) {
- done();
+ try {
+ // @ts-ignore
+ const result = fn.apply(this, args);
+ actual++;
+ if (actual >= expected) {
+ done();
+ }
+ return result;
+ } catch (err) {
+ if (err instanceof Error) done(err);
+ else if (err?.toString) done(new Error(err?.toString()));
+ else {
+ console.error("Unknown error", err);
+ done(new Error("Unknown error"));
+ }
}
- return result;
};
// Function instances have own properties that may be relevant.
// Let's replicate those properties to the returned function.