diff options
author | 2022-11-20 14:35:48 -0800 | |
---|---|---|
committer | 2022-11-20 14:35:48 -0800 | |
commit | e78f891acdf64f4809988d32a8270515958fa314 (patch) | |
tree | 91ab32b0d99aab394a1166cf3c826be94ed4bfd5 | |
parent | 948fdfe48265353f408c616112c79d8dba4b64ea (diff) | |
download | bun-e78f891acdf64f4809988d32a8270515958fa314.tar.gz bun-e78f891acdf64f4809988d32a8270515958fa314.tar.zst bun-e78f891acdf64f4809988d32a8270515958fa314.zip |
[bun:test] Fix bug with returning a non-promise object in a `test` or `it` function
-rw-r--r-- | src/bun.js/test/jest.zig | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index a9f4b13ac..935e5140c 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -912,33 +912,35 @@ pub const TestScope = struct { initial_value = js.JSObjectCallAsFunctionReturnValue(vm.global, callback, null, 0, null); } - if (initial_value.isException(vm.global.vm()) or initial_value.isError() or initial_value.isAggregateError(vm.global)) { - vm.runErrorHandler(initial_value, null); - return .{ .fail = active_test_expectation_counter.actual }; - } - - if (!initial_value.isEmptyOrUndefinedOrNull() and (initial_value.asPromise() != null or initial_value.asInternalPromise() != null)) { - if (this.promise != null) { - return .{ .pending = .{} }; + if (!initial_value.isEmptyOrUndefinedOrNull()) { + if (initial_value.isAnyError(vm.global)) { + vm.runErrorHandler(initial_value, null); + return .{ .fail = active_test_expectation_counter.actual }; } - var promise = initial_value.asPromise().?; - this.task = task; - - switch (promise.status(vm.global.vm())) { - .Rejected => { - vm.runErrorHandler(promise.result(vm.global.vm()), null); - return .{ .fail = active_test_expectation_counter.actual }; - }, - .Pending => { - task.promise_state = .pending; - _ = promise.asValue(vm.global).then(vm.global, task, onResolve, onReject); - return .{ .pending = {} }; - }, - - else => { - _ = promise.result(vm.global.vm()); - }, + if (initial_value.jsType() == .JSPromise) { + if (this.promise != null) { + return .{ .pending = .{} }; + } + + var promise = initial_value.asPromise().?; + this.task = task; + + switch (promise.status(vm.global.vm())) { + .Rejected => { + vm.runErrorHandler(promise.result(vm.global.vm()), null); + return .{ .fail = active_test_expectation_counter.actual }; + }, + .Pending => { + task.promise_state = .pending; + _ = promise.asValue(vm.global).then(vm.global, task, onResolve, onReject); + return .{ .pending = {} }; + }, + + else => { + _ = promise.result(vm.global.vm()); + }, + } } } |