Repository navigation
bun test #1825
Copy link
Copy link
Open
Labels
bun:testSomething related to the `bun test` runnerSomething related to the `bun test` runnertrackingAn umbrella issue for tracking big featuresAn umbrella issue for tracking big features
Description
Jest
describe()
- describe(name, fn)
- describe.each(table)(name, fn, timeout)
- describe.only(name, fn)
- describe.only.each(table)(name, fn)
- describe.skip(name, fn)
- describe.skip.each(table)(name, fn)
test()
- test(name, fn, timeout)
- test.concurrent(name, fn, timeout)
- test.concurrent.each(table)(name, fn, timeout)
- test.concurrent.only.each(table)(name, fn)
- test.concurrent.skip.each(table)(name, fn)
- test.each(table)(name, fn, timeout)
- test.failing(name, fn, timeout)
- test.failing.each(name, fn, timeout)
- test.only.failing(name, fn, timeout)
- test.skip.failing(name, fn, timeout)
- test.only(name, fn, timeout)
- test.only.each(table)(name, fn)
- test.skip(name, fn)
- test.skip.each(table)(name, fn)
- test.todo(name)
Lifecycle hooks
expect()
- expect(value)
- expect.extend(matchers)
- expect.anything()
- expect.any(constructor)
- expect.arrayContaining(array)
- expect.assertions(number)
- expect.closeTo(number, numDigits?)
- expect.hasAssertions()
- expect.not.arrayContaining(array)
- expect.not.objectContaining(object)
- expect.not.stringContaining(string)
- expect.not.stringMatching(string | regexp)
- expect.objectContaining(object)
- expect.stringContaining(string)
- expect.stringMatching(string | regexp)
- expect.addSnapshotSerializer(serializer)
- .not
- .resolves
- .rejects
- .toBe(value)
- .toHaveBeenCalled()
- .toHaveBeenCalledTimes(number)
- .toHaveBeenCalledWith(arg1, arg2, ...)
- .toHaveBeenLastCalledWith(arg1, arg2, ...)
- .toHaveBeenNthCalledWith(nthCall, arg1, arg2, ....)
- .toHaveReturned()
- .toHaveReturnedTimes(number)
- .toHaveReturnedWith(value)
- .toHaveLastReturnedWith(value)
- .toHaveNthReturnedWith(nthCall, value)
- .toHaveLength(number)
- .toHaveProperty(keyPath, value?)
- .toBeCloseTo(number, numDigits?)
- .toBeDefined()
- .toBeFalsy()
- .toBeGreaterThan(number | bigint)
- .toBeGreaterThanOrEqual(number | bigint)
- .toBeLessThan(number | bigint)
- .toBeLessThanOrEqual(number | bigint)
- .toBeInstanceOf(Class)
- .toBeNull()
- .toBeTruthy()
- .toBeUndefined()
- .toBeNaN()
- .toContain(item)
- .toContainEqual(item)
- .toEqual(value)
- .toMatch(regexp | string)
- .toMatchObject(object)
- .toMatchSnapshot(propertyMatchers?, hint?)
- .toMatchInlineSnapshot(propertyMatchers?, inlineSnapshot)
- .toStrictEqual(value)
- .toThrow(error?)
- .toThrowErrorMatchingSnapshot(hint?)
- .toThrowErrorMatchingInlineSnapshot(inlineSnapshot)
Mocks
- jest.fn(implementation?)
- jest.mock(module)
- jest.requireActual(module)
- jest.clearAllMocks
- jest.resetAllMocks
- jest.restoreAllMocks
- mockFn.getMockName()
- mockFn.mock.calls
- mockFn.mock.results
- mockFn.mock.instances
- mockFn.mock.contexts
- mockFn.mock.lastCall
- mockFn.mockClear()
- mockFn.mockReset()
- mockFn.mockRestore()
- mockFn.mockImplementation(fn)
- mockFn.mockImplementationOnce(fn)
- mockFn.mockName(name)
- mockFn.mockReturnThis()
- mockFn.mockReturnValue(value)
- mockFn.mockReturnValueOnce(value)
- mockFn.mockResolvedValue(value)
- mockFn.mockResolvedValueOnce(value)
- mockFn.mockRejectedValue(value)
- mockFn.mockRejectedValueOnce(value)
- mockFn.withImplementation(fn, callback)
Misc
Vitest
expect()
Mocks
- vi.fn
- vi.mock
- vi.doMock
- vi.mocked
- vi.spyOn
- vi.unmock
- vi.importActual
- vi.importMock
- vi.resetAllMocks
- vi.dynamicImportSettled
- vi.resetModules
- vi.restoreAllMocks
- vi.stubEnv
- vi.unstubAllEnvs
- vi.stubGlobal
- vi.unstubAllGlobals
- vi.doUnmock
Timers
- vi.advanceTimersByTime
- vi.advanceTimersByTimeAsync
- vi.advanceTimersToNextTimer
- vi.advanceTimersToNextTimerAsync
- vi.getTimerCount
- vi.clearAllTimers
- vi.getMockedSystemTime
- vi.getRealSystemTime
- vi.restoreCurrentDate
- vi.runAllTicks
- vi.runAllTimers
- vi.runAllTimersAsync
- vi.runOnlyPendingTimers
- vi.runOnlyPendingTimersAsync
- vi.setSystemTime
- vi.useFakeTimers
- vi.useRealTimers
Misc
jest-extended
expect()
- .pass(message)
- .fail(message)
- .toBeEmpty()
- .toBeOneOf([members])
- .toBeNil()
- .toBeArray()
- .toBeArrayOfSize()
- .toIncludeAllMembers([members])
- .toIncludeAllPartialMembers([members])
- .toIncludeAnyMembers([members])
- .toIncludeSameMembers([members])
- .toPartiallyContain(member)
- .toSatisfyAll(predicate)
- .toSatisfyAny(predicate)
- .toBeInRange(min, max)
- .toBeBoolean()
- .toBeTrue()
- .toBeFalse()
- .toBeDate()
- .toBeValidDate()
- .toBeAfter(date)
- .toBeBefore(date)
- .toBeAfterOrEqualTo(date)
- .toBeBeforeOrEqualTo(date)
- .toBeBetween(startDate, endDate)
- .toBeFunction()
- .toThrowWithMessage()
- .toHaveBeenCalledBefore()
- .toHaveBeenCalledAfter()
- .toHaveBeenCalledOnce()
- .toHaveBeenCalledOnceWith()
- .toBeNumber()
- .toBeNaN()
- .toBeFinite()
- .toBePositive()
- .toBeNegative()
- .toBeEven()
- .toBeOdd()
- .toBeWithin(start, end)
- .toBeInteger()
- .toBeObject()
- .toBeEmptyObject()
- .toContainKey(key)
- .toContainKeys([keys])
- .toContainAllKeys([keys])
- .toContainAnyKeys([keys])
- .toContainValue(value)
- .toContainValues([values])
- .toContainAllValues([values])
- .toContainAnyValues([values])
- .toContainEntry([key, value])
- .toContainEntries([[key, value]])
- .toContainAllEntries([[key, value]])
- .toContainAnyEntries([[key, value]])
- .toBeExtensible()
- .toBeFrozen()
- .toBeSealed()
- .toResolve()
- .toReject()
- .toBeString()
- .toBeHexadecimal(string)
- .toBeDateString(string)
- .toEqualCaseInsensitive(string)
- .toStartWith(prefix)
- .toEndWith(suffix)
- .toInclude(substring)
- .toIncludeRepeated(substring, times)
- .toIncludeMultiple([substring])
- .toEqualIgnoringWhitespace(string)
- .toBeSymbol()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bun:testSomething related to the `bun test` runnerSomething related to the `bun test` runnertrackingAn umbrella issue for tracking big featuresAn umbrella issue for tracking big features
Activity
[-]Promote `bun wiptest` to `bun test`[/-][+]`bun test`[/+]useafterfree commentedon Jan 18, 2023
ts-jestdoes some magical hoisting withmock*functions which may or may not be a challenge with bun:swc-project/swc#5448 (comment)
nskins commentedon Mar 11, 2023
This issue can be updated to check off these four (they were implemented in PR #1573):
.toBeGreaterThan(number | bigint).toBeGreaterThanOrEqual(number | bigint).toBeLessThan(number | bigint).toBeLessThanOrEqual(number | bigint)erikshestopal commentedon Jun 26, 2023
Should
jest.mockbe added as well? Doesn't seem to be tracked.Jarred-Sumner commentedon Jun 26, 2023
@erikshestopal please give it a try in the canary build, a lot of it is in there
brapifra commentedon Jun 27, 2023
jest.clearAllMocks()is also missing 👀 🙏[-]`bun test`[/-][+]`bun test` [Converted to "`bun test`" project][/+][-]`bun test` [Converted to "`bun test`" project][/-][+]`bun test`[/+]itsezc commentedon Jul 7, 2023
Would there be any scope to add DOM matchers? If so, I'd love for some parity with the jest-dom library.
Hanaasagi commentedon Jul 7, 2023
toThrowErroris missing. It's a alias fortoThrow.Ref: https://jestjs.io/docs/expect#tothrowerror
riywo commentedon Jul 10, 2023
test.eachanddescribe.eachare super helpful to build data-driven unit tests.simylein commentedon Jul 14, 2023
I am proposing adding https://vitest.dev/api/expect-typeof.html to the vitest list.
ghiscoding commentedon Aug 8, 2023
It's being worked on in PR #4047
101 remaining items
janhesters commentedon Oct 24, 2025
Please add
vi.onTestFinishedto the list. A super useful hook for creating reusable logic, such as:Here is a temporary workaround:
pfgithub commentedon Oct 24, 2025
@janhesters We support afterAll inside the test callback, so until onTestFinished is added, you can use it as a workaround:
However, this will run in a different order than onTestFinished. It will run before the test's afterEach hooks.
janhesters commentedon Oct 24, 2025
@pfgithub Interesting, thank you for sharing that!
janhesters commentedon Oct 26, 2025
Feature Request: Per-Test-File Preload Configuration
Edit: Created #26693
Use Case
When testing full-stack applications, different test files often have conflicting requirements:
Cookieheaders onRequestobjects)Currently, the global
preloadinbunfig.tomlapplies to ALL tests, making it impossible to conditionally load environment-specific setup based on the test file being executed.Current Problem
HappyDOM enforces browser security restrictions, including preventing JavaScript from setting
Cookieheaders onRequestobjects. This breaks authenticated route testing:Current Workarounds
Monkey-patch the Request constructor (what we're doing now)
Separate test commands
Proposed Solution
Expose test file information to preload scripts via environment variable:
Then in
bunfig.toml:Alternative API
Or provide a more explicit API:
Related
testEnvironmentper-file:@jest-environment jsdomWould love to see this functionality in Bun! The test runner is already incredibly fast - this would make it even more versatile for full-stack testing. 🚀
quantizor commentedon Nov 1, 2025
@Jarred-Sumner is
addSnapshotSerializergetting implemented soon? it's listed in the docs but says not implemented in code https://bun.sh/docs/test/snapshots#custom-serializersthi-marques commentedon Nov 18, 2025
I did not found any mention to
jest.replaceProperty. It would be great to have it on the roadmap, it's very handy.Azarattum commentedon Jan 28, 2026
Would be nice to be able to use
--cpu-profwithbun test.janhesters commentedon Feb 3, 2026
@pfgithub created a PR for my second feature request, the per file configs here: #26693
ivands commentedon Feb 9, 2026
Could we also add
expect.addEqualityTesters.This is needed if you wanna add custom logic to check the equality of custom objects.
For example: a custom
BigFloatimplementation.ansulagrawal commentedon Apr 11, 2026
@pfgithub and team, can we add counts and percentages here?
For example:
Just a suggestion—what do you think?
tim-soft commentedon Apr 15, 2026
@Electroid Last update to OP's post was ~6 months ago, is there a more up-to-date list for Bun's Jest support?
feat: support tagged template literal format for it.each/test.each
feat: support tagged template literal format for it.each/test.each
feat: support tagged template literal format for it.each/test.each
'vi' was missing from bun test globals (#23674)