
Research
/Security News
Mini Shai-Hulud Campaign Hits Red Hat Cloud Services npm Packages
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.
bun-test-env-dom
Advanced tools
bun-test-env-dom is a preload library that provides a ready-to-use DOM for testing
A preload library for Bun that provides a ready-to-use DOM environment for testing. It automatically sets up happy-dom and enables proper snapshot testing for React and HTML elements with beautifully formatted output.
Without this library, Bun's snapshot testing outputs unreadable React internals (FiberNode, stateNode, etc.):

With bun-test-env-dom, snapshots are clean, formatted HTML that's easy to read and review:

bun add -d bun-test-env-dom
Add the following to your bunfig.toml:
[test]
preload = ["bun-test-env-dom"]
That's it! The DOM environment is automatically configured when tests run.
Snapshot testing works seamlessly with both React elements and HTML elements. The HTML output is automatically formatted for readable snapshots.
import { expect, test } from 'bun:test'
import { render } from 'bun-test-env-dom'
test('React element snapshot', () => {
expect(<Component />).toMatchSnapshot()
})
test('HTML element snapshot', () => {
const { container } = render(<Component />)
expect(container).toMatchSnapshot()
})
All functions from @testing-library/react and @testing-library/user-event are re-exported, so you can import directly from bun-test-env-dom:
import { render, screen, fireEvent } from 'bun-test-env-dom'
describe('HomePage', () => {
it('should render', () => {
const { container } = render(<HomePage />)
expect(container).toMatchSnapshot()
})
})
All additional matchers from @testing-library/jest-dom are fully typed:
import { expect, test } from 'bun:test'
import { render } from 'bun-test-env-dom'
test('custom matchers', () => {
const { getByRole } = render(<Button pressed>Click me</Button>)
expect(getByRole('button')).toBePressed()
expect(getByRole('button')).toBeVisible()
expect(getByRole('button')).toHaveTextContent('Click me')
})
Apache-2.0
FAQs
bun-test-env-dom is a preload library that provides a ready-to-use DOM for testing
We found that bun-test-env-dom demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.

Security News
The Rust project is moving toward formal rules on LLM use in contributions after months of internal debate over maintainer burden, code quality, and contributor experience.