Learn how to use bun test to write automated unit tests with Bun's built-in test runner. bun test runner is fast, Jest-compatible, and allows for native Typescript support.
We go through writing basic unit tests, organizing your tests, test lifecycle operations, conditional tests/skipping, timeout/retries, asynchronous tests, preload scripts, DOM & React Component support, and two different methods of mocking.
Thanks for watching!
JSON Placeholder Endpoint: https://jsonplaceholder.typicode.com/...
React Component Support Install Commands:
bun i -D @types/react @testing-library/jest-dom @testing-library/react
bun i @happy-dom/global-registrator
Bun's Test Runner: https://bun.com/docs/test
Bun Website: https://bun.com
[00:00] - Intro & What is Bun Test
[00:38] - Project Setup & Basic Functions
[01:23] - Writing Your First Test
[03:39] - Using test.each for Multiple Cases
[05:27] - Grouping Tests with describe
[06:44] - Filtering Tests with the -t Flag
[07:18] - Testing for Expected Errors
[07:53] - Using Objects in test.each
[09:44] - Lifecycle Hooks (beforeAll, beforeEach)
[10:31] - Conditional Tests (if, skip, todo)
[11:34] - Testing Asynchronous API Calls
[13:55] - Test Timeouts and Retries
[14:37] - Mocking System Time
[16:06] - DOM Testing & React Components Setup
[17:42] - Writing a React Component Test
[19:21] - Intro to Mocking & Database Setup
[23:07] - Mocking Dependencies with mock()
[27:08] - Intercepting Methods with spyOn()
[30:04] - Outro