Open
Description
What version of Bun is running?
v1.2.4
What platform is your computer?
Darwin 24.3.0 arm64 arm
What steps can reproduce the bug?
const ctx = new AsyncLocalStorage<Store>();
import { afterEach, beforeEach, expect, spyOn, test } from "bun:test";
import { overview } from './index.js';
import { ctx } from "../ctx/index.js";
import { mockStore } from "../mocks/store.js";
let mockedFetch = spyOn(globalThis, 'fetch')
mockedFetch.mockImplementation(async () => new Response("{}"))
beforeEach(() => {
ctx.enterWith(mockStore)
})
// Reset mocks between tests
afterEach(() => {
mockedFetch.mockReset();
});
test('overview no retries', async () => ctx.run({ ...mockStore, retryAttempts: -1 }, () => {
mockedFetch.mockImplementationOnce(async () => new Response("{}", { status: 500 }))
expect(overview()).rejects.toThrow("Failed to fetch overview. Maximum retries exceeded.");
expect(mockedFetch).toBeCalledTimes(0);
}))
test('overview positive retries', async () => ctx.run({ ...mockStore, retryAttempts: 3 }, () => {
mockedFetch.mockImplementationOnce(async () => new Response("{}", { status: 500 }))
mockedFetch.mockImplementationOnce(async () => new Response("{}", { status: 500 }))
mockedFetch.mockImplementation(async () => new Response("{}", { status: 200 }))
expect(overview()).resolves.toBeTruthy();
expect(mockedFetch).toBeCalledTimes(3);
}))
And run
bun test
I got an error after test finished
36 | mockedFetch.mockImplementationOnce(async () => new Response("{}", { status: 500 }))
37 | expect(overview()).rejects.toThrow("Failed to fetch overview. Maximum retries exceeded.");
38 | expect(mockedFetch).toBeCalledTimes(0);
39 | }))
40 |
41 | test('overview positive retries', async () => ctx.run({ ...mockStore, retryAttempts: 3 }, () => {
^
TypeError: undefined is not an object (evaluating 'get')
at run (node:async_hooks:72:37)
at <anonymous> (index.spec.ts:41:35)
✗ overview positive retries [0.38ms]
What is the expected behavior?
Tests finished without error
What do you see instead?
41 | test('overview positive retries', async () => ctx.run({ ...mockStore, retryAttempts: 3 }, () => {
^
TypeError: undefined is not an object (evaluating 'get')
at run (node:async_hooks:72:37)
at <anonymous> (index.spec.ts:41:35)
✗ overview positive retries [0.38ms]
Additional information
No response