Back to articles
Bun Test Has a Free Built-in Test Runner — Here's Why You Don't Need Jest Anymore

Bun Test Has a Free Built-in Test Runner — Here's Why You Don't Need Jest Anymore

via Dev.to JavaScriptAlex Spinov

Jest takes 10 seconds to start. Bun's test runner starts in milliseconds. And it is built right in — no install needed. Quick Start # No installation needed — bun has it built in bun test // math.test.ts import { expect , test , describe , beforeEach , mock } from " bun:test " ; describe ( " math " , () => { test ( " addition " , () => { expect ( 2 + 2 ). toBe ( 4 ); }); test ( " multiplication " , () => { expect ( 3 * 7 ). toBe ( 21 ); }); }); Jest-Compatible API import { expect , test , describe , beforeEach , afterEach , beforeAll , afterAll } from " bun:test " ; // All Jest matchers work expect ( value ). toBe ( expected ); expect ( value ). toEqual ( expected ); expect ( value ). toBeTruthy (); expect ( value ). toContain ( item ); expect ( value ). toThrow (); expect ( value ). toMatchSnapshot (); expect ( value ). toHaveBeenCalled (); expect ( value ). toHaveBeenCalledWith ( args ); Mocking import { mock , spyOn } from " bun:test " ; // Mock a function const mockFn = mock (() =>

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles