We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v1.2.4
Darwin 24.3.0 arm64 arm
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]
Tests finished without error
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]
No response
The text was updated successfully, but these errors were encountered:
If i make something like this, i got an extended error
expect(overview).not.toThrow();
67 | throw e; 68 | } finally { 69 | if (!wasDisabled) { 70 | var context2 = get(); 71 | if (context2 === context && contextWasAlreadyInit) 72 | else if (context2 = context2.slice(), hasPrevious) ^ TypeError: undefined is not an object (evaluating 'get') at run (node:async_hooks:72:37) ✗ overview positive retries [0.25ms]
Sorry, something went wrong.
But if i use enterWith, instead of run, all works fine.
test('overview positive retries', () => { ctx.enterWith({ ...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).not.toThrow(); expect(mockedFetch).toBeCalledTimes(3); })
No branches or pull requests
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?
And run
I got an error after test finished
What is the expected behavior?
Tests finished without error
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: