From b8993dbd780d4afd5ef9f7d86fe931aa651babe6 Mon Sep 17 00:00:00 2001 From: Zilin Zhu Date: Sat, 6 Aug 2022 17:32:32 +0800 Subject: [PATCH] [wiptest] fix calling toBe in describe (#1000) --- src/bun.js/test/jest.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index 7922c49409..6cbfe32268 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -365,6 +365,16 @@ pub const Expect = struct { ); return js.JSValueMakeUndefined(ctx); } + if (this.scope.tests.items.len <= this.test_id) { + JSC.JSError( + getAllocator(ctx), + ".toBe() called in wrong scope", + .{}, + ctx, + exception, + ); + return js.JSValueMakeUndefined(ctx); + } this.scope.tests.items[this.test_id].counter.actual += 1; const left = JSValue.fromRef(arguments[0]); left.ensureStillAlive(); @@ -418,6 +428,16 @@ pub const Expect = struct { ); return js.JSValueMakeUndefined(ctx); } + if (this.scope.tests.items.len <= this.test_id) { + JSC.JSError( + getAllocator(ctx), + ".toHaveLength() called in wrong scope", + .{}, + ctx, + exception, + ); + return js.JSValueMakeUndefined(ctx); + } this.scope.tests.items[this.test_id].counter.actual += 1; const expected = JSC.JSValue.fromRef(arguments[0]).toU32();