@depup/bun-types 1.3.11-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/CLAUDE.md +105 -0
  2. package/README.md +25 -0
  3. package/bun.d.ts +8712 -0
  4. package/bun.ns.d.ts +5 -0
  5. package/bundle.d.ts +74 -0
  6. package/changes.json +5 -0
  7. package/deprecated.d.ts +184 -0
  8. package/devserver.d.ts +187 -0
  9. package/docs/README.md +28 -0
  10. package/docs/bundler/bytecode.mdx +447 -0
  11. package/docs/bundler/css.mdx +1024 -0
  12. package/docs/bundler/esbuild.mdx +304 -0
  13. package/docs/bundler/executables.mdx +1318 -0
  14. package/docs/bundler/fullstack.mdx +1086 -0
  15. package/docs/bundler/hot-reloading.mdx +229 -0
  16. package/docs/bundler/html-static.mdx +498 -0
  17. package/docs/bundler/index.mdx +1840 -0
  18. package/docs/bundler/loaders.mdx +451 -0
  19. package/docs/bundler/macros.mdx +328 -0
  20. package/docs/bundler/minifier.mdx +1286 -0
  21. package/docs/bundler/plugins.mdx +477 -0
  22. package/docs/bundler/standalone-html.mdx +314 -0
  23. package/docs/feedback.mdx +75 -0
  24. package/docs/guides/binary/arraybuffer-to-array.mdx +29 -0
  25. package/docs/guides/binary/arraybuffer-to-blob.mdx +26 -0
  26. package/docs/guides/binary/arraybuffer-to-buffer.mdx +27 -0
  27. package/docs/guides/binary/arraybuffer-to-string.mdx +17 -0
  28. package/docs/guides/binary/arraybuffer-to-typedarray.mdx +41 -0
  29. package/docs/guides/binary/blob-to-arraybuffer.mdx +16 -0
  30. package/docs/guides/binary/blob-to-dataview.mdx +16 -0
  31. package/docs/guides/binary/blob-to-stream.mdx +16 -0
  32. package/docs/guides/binary/blob-to-string.mdx +17 -0
  33. package/docs/guides/binary/blob-to-typedarray.mdx +16 -0
  34. package/docs/guides/binary/buffer-to-arraybuffer.mdx +16 -0
  35. package/docs/guides/binary/buffer-to-blob.mdx +16 -0
  36. package/docs/guides/binary/buffer-to-readablestream.mdx +43 -0
  37. package/docs/guides/binary/buffer-to-string.mdx +27 -0
  38. package/docs/guides/binary/buffer-to-typedarray.mdx +16 -0
  39. package/docs/guides/binary/dataview-to-string.mdx +17 -0
  40. package/docs/guides/binary/typedarray-to-arraybuffer.mdx +27 -0
  41. package/docs/guides/binary/typedarray-to-blob.mdx +18 -0
  42. package/docs/guides/binary/typedarray-to-buffer.mdx +16 -0
  43. package/docs/guides/binary/typedarray-to-dataview.mdx +16 -0
  44. package/docs/guides/binary/typedarray-to-readablestream.mdx +43 -0
  45. package/docs/guides/binary/typedarray-to-string.mdx +18 -0
  46. package/docs/guides/deployment/aws-lambda.mdx +204 -0
  47. package/docs/guides/deployment/digital-ocean.mdx +161 -0
  48. package/docs/guides/deployment/google-cloud-run.mdx +194 -0
  49. package/docs/guides/deployment/railway.mdx +145 -0
  50. package/docs/guides/deployment/render.mdx +82 -0
  51. package/docs/guides/deployment/vercel.mdx +97 -0
  52. package/docs/guides/ecosystem/astro.mdx +82 -0
  53. package/docs/guides/ecosystem/discordjs.mdx +80 -0
  54. package/docs/guides/ecosystem/docker.mdx +151 -0
  55. package/docs/guides/ecosystem/drizzle.mdx +195 -0
  56. package/docs/guides/ecosystem/elysia.mdx +31 -0
  57. package/docs/guides/ecosystem/express.mdx +43 -0
  58. package/docs/guides/ecosystem/gel.mdx +261 -0
  59. package/docs/guides/ecosystem/hono.mdx +47 -0
  60. package/docs/guides/ecosystem/mongoose.mdx +92 -0
  61. package/docs/guides/ecosystem/neon-drizzle.mdx +234 -0
  62. package/docs/guides/ecosystem/neon-serverless-postgres.mdx +60 -0
  63. package/docs/guides/ecosystem/nextjs.mdx +103 -0
  64. package/docs/guides/ecosystem/nuxt.mdx +96 -0
  65. package/docs/guides/ecosystem/pm2.mdx +55 -0
  66. package/docs/guides/ecosystem/prisma-postgres.mdx +169 -0
  67. package/docs/guides/ecosystem/prisma.mdx +164 -0
  68. package/docs/guides/ecosystem/qwik.mdx +114 -0
  69. package/docs/guides/ecosystem/react.mdx +52 -0
  70. package/docs/guides/ecosystem/remix.mdx +97 -0
  71. package/docs/guides/ecosystem/sentry.mdx +54 -0
  72. package/docs/guides/ecosystem/solidstart.mdx +62 -0
  73. package/docs/guides/ecosystem/ssr-react.mdx +49 -0
  74. package/docs/guides/ecosystem/stric.mdx +54 -0
  75. package/docs/guides/ecosystem/sveltekit.mdx +138 -0
  76. package/docs/guides/ecosystem/systemd.mdx +114 -0
  77. package/docs/guides/ecosystem/tanstack-start.mdx +791 -0
  78. package/docs/guides/ecosystem/upstash.mdx +87 -0
  79. package/docs/guides/ecosystem/vite.mdx +77 -0
  80. package/docs/guides/html-rewriter/extract-links.mdx +71 -0
  81. package/docs/guides/html-rewriter/extract-social-meta.mdx +97 -0
  82. package/docs/guides/http/cluster.mdx +69 -0
  83. package/docs/guides/http/fetch-unix.mdx +35 -0
  84. package/docs/guides/http/fetch.mdx +26 -0
  85. package/docs/guides/http/file-uploads.mdx +97 -0
  86. package/docs/guides/http/hot.mdx +28 -0
  87. package/docs/guides/http/proxy.mdx +50 -0
  88. package/docs/guides/http/server.mdx +48 -0
  89. package/docs/guides/http/simple.mdx +20 -0
  90. package/docs/guides/http/sse.mdx +91 -0
  91. package/docs/guides/http/stream-file.mdx +50 -0
  92. package/docs/guides/http/stream-iterator.mdx +49 -0
  93. package/docs/guides/http/stream-node-streams-in-bun.mdx +22 -0
  94. package/docs/guides/http/tls.mdx +32 -0
  95. package/docs/guides/index.mdx +10 -0
  96. package/docs/guides/install/add-dev.mdx +28 -0
  97. package/docs/guides/install/add-git.mdx +40 -0
  98. package/docs/guides/install/add-optional.mdx +27 -0
  99. package/docs/guides/install/add-peer.mdx +45 -0
  100. package/docs/guides/install/add-tarball.mdx +35 -0
  101. package/docs/guides/install/add.mdx +44 -0
  102. package/docs/guides/install/azure-artifacts.mdx +76 -0
  103. package/docs/guides/install/cicd.mdx +43 -0
  104. package/docs/guides/install/custom-registry.mdx +32 -0
  105. package/docs/guides/install/from-npm-install-to-bun-install.mdx +230 -0
  106. package/docs/guides/install/git-diff-bun-lockfile.mdx +48 -0
  107. package/docs/guides/install/jfrog-artifactory.mdx +28 -0
  108. package/docs/guides/install/npm-alias.mdx +25 -0
  109. package/docs/guides/install/registry-scope.mdx +40 -0
  110. package/docs/guides/install/trusted.mdx +52 -0
  111. package/docs/guides/install/workspaces.mdx +70 -0
  112. package/docs/guides/install/yarnlock.mdx +51 -0
  113. package/docs/guides/process/argv.mdx +66 -0
  114. package/docs/guides/process/ctrl-c.mdx +18 -0
  115. package/docs/guides/process/ipc.mdx +69 -0
  116. package/docs/guides/process/nanoseconds.mdx +15 -0
  117. package/docs/guides/process/os-signals.mdx +31 -0
  118. package/docs/guides/process/spawn-stderr.mdx +34 -0
  119. package/docs/guides/process/spawn-stdout.mdx +28 -0
  120. package/docs/guides/process/spawn.mdx +43 -0
  121. package/docs/guides/process/stdin.mdx +62 -0
  122. package/docs/guides/read-file/arraybuffer.mdx +30 -0
  123. package/docs/guides/read-file/buffer.mdx +21 -0
  124. package/docs/guides/read-file/exists.mdx +18 -0
  125. package/docs/guides/read-file/json.mdx +19 -0
  126. package/docs/guides/read-file/mime.mdx +22 -0
  127. package/docs/guides/read-file/stream.mdx +28 -0
  128. package/docs/guides/read-file/string.mdx +24 -0
  129. package/docs/guides/read-file/uint8array.mdx +23 -0
  130. package/docs/guides/read-file/watch.mdx +66 -0
  131. package/docs/guides/runtime/build-time-constants.mdx +295 -0
  132. package/docs/guides/runtime/cicd.mdx +45 -0
  133. package/docs/guides/runtime/codesign-macos-executable.mdx +61 -0
  134. package/docs/guides/runtime/define-constant.mdx +149 -0
  135. package/docs/guides/runtime/delete-directory.mdx +39 -0
  136. package/docs/guides/runtime/delete-file.mdx +21 -0
  137. package/docs/guides/runtime/heap-snapshot.mdx +28 -0
  138. package/docs/guides/runtime/import-html.mdx +15 -0
  139. package/docs/guides/runtime/import-json.mdx +46 -0
  140. package/docs/guides/runtime/import-json5.mdx +74 -0
  141. package/docs/guides/runtime/import-toml.mdx +32 -0
  142. package/docs/guides/runtime/import-yaml.mdx +104 -0
  143. package/docs/guides/runtime/read-env.mdx +37 -0
  144. package/docs/guides/runtime/set-env.mdx +51 -0
  145. package/docs/guides/runtime/shell.mdx +42 -0
  146. package/docs/guides/runtime/timezone.mdx +38 -0
  147. package/docs/guides/runtime/tsconfig-paths.mdx +31 -0
  148. package/docs/guides/runtime/typescript.mdx +51 -0
  149. package/docs/guides/runtime/vscode-debugger.mdx +47 -0
  150. package/docs/guides/runtime/web-debugger.mdx +103 -0
  151. package/docs/guides/streams/node-readable-to-arraybuffer.mdx +13 -0
  152. package/docs/guides/streams/node-readable-to-blob.mdx +13 -0
  153. package/docs/guides/streams/node-readable-to-json.mdx +14 -0
  154. package/docs/guides/streams/node-readable-to-string.mdx +14 -0
  155. package/docs/guides/streams/node-readable-to-uint8array.mdx +13 -0
  156. package/docs/guides/streams/to-array.mdx +16 -0
  157. package/docs/guides/streams/to-arraybuffer.mdx +16 -0
  158. package/docs/guides/streams/to-blob.mdx +16 -0
  159. package/docs/guides/streams/to-buffer.mdx +17 -0
  160. package/docs/guides/streams/to-json.mdx +16 -0
  161. package/docs/guides/streams/to-string.mdx +16 -0
  162. package/docs/guides/streams/to-typedarray.mdx +24 -0
  163. package/docs/guides/test/bail.mdx +24 -0
  164. package/docs/guides/test/concurrent-test-glob.mdx +146 -0
  165. package/docs/guides/test/coverage-threshold.mdx +67 -0
  166. package/docs/guides/test/coverage.mdx +49 -0
  167. package/docs/guides/test/happy-dom.mdx +73 -0
  168. package/docs/guides/test/migrate-from-jest.mdx +125 -0
  169. package/docs/guides/test/mock-clock.mdx +50 -0
  170. package/docs/guides/test/mock-functions.mdx +70 -0
  171. package/docs/guides/test/rerun-each.mdx +16 -0
  172. package/docs/guides/test/run-tests.mdx +116 -0
  173. package/docs/guides/test/skip-tests.mdx +43 -0
  174. package/docs/guides/test/snapshot.mdx +102 -0
  175. package/docs/guides/test/spy-on.mdx +49 -0
  176. package/docs/guides/test/svelte-test.mdx +113 -0
  177. package/docs/guides/test/testing-library.mdx +93 -0
  178. package/docs/guides/test/timeout.mdx +17 -0
  179. package/docs/guides/test/todo-tests.mdx +74 -0
  180. package/docs/guides/test/update-snapshots.mdx +49 -0
  181. package/docs/guides/test/watch-mode.mdx +24 -0
  182. package/docs/guides/util/base64.mdx +17 -0
  183. package/docs/guides/util/deep-equals.mdx +41 -0
  184. package/docs/guides/util/deflate.mdx +20 -0
  185. package/docs/guides/util/detect-bun.mdx +28 -0
  186. package/docs/guides/util/entrypoint.mdx +19 -0
  187. package/docs/guides/util/escape-html.mdx +24 -0
  188. package/docs/guides/util/file-url-to-path.mdx +16 -0
  189. package/docs/guides/util/gzip.mdx +20 -0
  190. package/docs/guides/util/hash-a-password.mdx +56 -0
  191. package/docs/guides/util/import-meta-dir.mdx +15 -0
  192. package/docs/guides/util/import-meta-file.mdx +15 -0
  193. package/docs/guides/util/import-meta-path.mdx +15 -0
  194. package/docs/guides/util/javascript-uuid.mdx +25 -0
  195. package/docs/guides/util/main.mdx +43 -0
  196. package/docs/guides/util/path-to-file-url.mdx +16 -0
  197. package/docs/guides/util/sleep.mdx +24 -0
  198. package/docs/guides/util/upgrade.mdx +93 -0
  199. package/docs/guides/util/version.mdx +23 -0
  200. package/docs/guides/util/which-path-to-executable-bin.mdx +17 -0
  201. package/docs/guides/websocket/compression.mdx +33 -0
  202. package/docs/guides/websocket/context.mdx +79 -0
  203. package/docs/guides/websocket/pubsub.mdx +43 -0
  204. package/docs/guides/websocket/simple.mdx +38 -0
  205. package/docs/guides/write-file/append.mdx +54 -0
  206. package/docs/guides/write-file/basic.mdx +46 -0
  207. package/docs/guides/write-file/blob.mdx +30 -0
  208. package/docs/guides/write-file/cat.mdx +19 -0
  209. package/docs/guides/write-file/file-cp.mdx +18 -0
  210. package/docs/guides/write-file/filesink.mdx +54 -0
  211. package/docs/guides/write-file/response.mdx +19 -0
  212. package/docs/guides/write-file/stdout.mdx +23 -0
  213. package/docs/guides/write-file/stream.mdx +19 -0
  214. package/docs/guides/write-file/unlink.mdx +18 -0
  215. package/docs/index.mdx +133 -0
  216. package/docs/installation.mdx +372 -0
  217. package/docs/pm/bunx.mdx +91 -0
  218. package/docs/pm/catalogs.mdx +292 -0
  219. package/docs/pm/cli/add.mdx +179 -0
  220. package/docs/pm/cli/audit.mdx +60 -0
  221. package/docs/pm/cli/info.mdx +70 -0
  222. package/docs/pm/cli/install.mdx +591 -0
  223. package/docs/pm/cli/link.mdx +61 -0
  224. package/docs/pm/cli/outdated.mdx +197 -0
  225. package/docs/pm/cli/patch.mdx +69 -0
  226. package/docs/pm/cli/pm.mdx +323 -0
  227. package/docs/pm/cli/publish.mdx +131 -0
  228. package/docs/pm/cli/remove.mdx +16 -0
  229. package/docs/pm/cli/update.mdx +140 -0
  230. package/docs/pm/cli/why.mdx +84 -0
  231. package/docs/pm/filter.mdx +127 -0
  232. package/docs/pm/global-cache.mdx +72 -0
  233. package/docs/pm/isolated-installs.mdx +220 -0
  234. package/docs/pm/lifecycle.mdx +64 -0
  235. package/docs/pm/lockfile.mdx +64 -0
  236. package/docs/pm/npmrc.mdx +245 -0
  237. package/docs/pm/overrides.mdx +83 -0
  238. package/docs/pm/scopes-registries.mdx +35 -0
  239. package/docs/pm/security-scanner-api.mdx +95 -0
  240. package/docs/pm/workspaces.mdx +115 -0
  241. package/docs/project/benchmarking.mdx +296 -0
  242. package/docs/project/bindgen.mdx +223 -0
  243. package/docs/project/building-windows.mdx +143 -0
  244. package/docs/project/contributing.mdx +366 -0
  245. package/docs/project/feedback.mdx +20 -0
  246. package/docs/project/license.mdx +78 -0
  247. package/docs/project/roadmap.mdx +8 -0
  248. package/docs/quickstart.mdx +251 -0
  249. package/docs/runtime/archive.mdx +452 -0
  250. package/docs/runtime/auto-install.mdx +97 -0
  251. package/docs/runtime/binary-data.mdx +846 -0
  252. package/docs/runtime/bun-apis.mdx +60 -0
  253. package/docs/runtime/bunfig.mdx +765 -0
  254. package/docs/runtime/c-compiler.mdx +204 -0
  255. package/docs/runtime/child-process.mdx +659 -0
  256. package/docs/runtime/color.mdx +267 -0
  257. package/docs/runtime/console.mdx +67 -0
  258. package/docs/runtime/cookies.mdx +454 -0
  259. package/docs/runtime/cron.mdx +358 -0
  260. package/docs/runtime/csrf.mdx +171 -0
  261. package/docs/runtime/debugger.mdx +335 -0
  262. package/docs/runtime/environment-variables.mdx +231 -0
  263. package/docs/runtime/ffi.mdx +567 -0
  264. package/docs/runtime/file-io.mdx +306 -0
  265. package/docs/runtime/file-system-router.mdx +118 -0
  266. package/docs/runtime/file-types.mdx +482 -0
  267. package/docs/runtime/glob.mdx +181 -0
  268. package/docs/runtime/globals.mdx +72 -0
  269. package/docs/runtime/hashing.mdx +315 -0
  270. package/docs/runtime/html-rewriter.mdx +333 -0
  271. package/docs/runtime/http/cookies.mdx +79 -0
  272. package/docs/runtime/http/error-handling.mdx +40 -0
  273. package/docs/runtime/http/metrics.mdx +36 -0
  274. package/docs/runtime/http/routing.mdx +289 -0
  275. package/docs/runtime/http/server.mdx +672 -0
  276. package/docs/runtime/http/tls.mdx +101 -0
  277. package/docs/runtime/http/websockets.mdx +414 -0
  278. package/docs/runtime/index.mdx +223 -0
  279. package/docs/runtime/json5.mdx +271 -0
  280. package/docs/runtime/jsonl.mdx +188 -0
  281. package/docs/runtime/jsx.mdx +115 -0
  282. package/docs/runtime/markdown.mdx +381 -0
  283. package/docs/runtime/module-resolution.mdx +374 -0
  284. package/docs/runtime/networking/dns.mdx +111 -0
  285. package/docs/runtime/networking/fetch.mdx +484 -0
  286. package/docs/runtime/networking/tcp.mdx +239 -0
  287. package/docs/runtime/networking/udp.mdx +180 -0
  288. package/docs/runtime/node-api.mdx +19 -0
  289. package/docs/runtime/nodejs-compat.mdx +468 -0
  290. package/docs/runtime/plugins.mdx +419 -0
  291. package/docs/runtime/redis.mdx +583 -0
  292. package/docs/runtime/repl.mdx +176 -0
  293. package/docs/runtime/s3.mdx +881 -0
  294. package/docs/runtime/secrets.mdx +340 -0
  295. package/docs/runtime/semver.mdx +57 -0
  296. package/docs/runtime/shell.mdx +637 -0
  297. package/docs/runtime/sql.mdx +1404 -0
  298. package/docs/runtime/sqlite.mdx +721 -0
  299. package/docs/runtime/streams.mdx +232 -0
  300. package/docs/runtime/templating/create.mdx +269 -0
  301. package/docs/runtime/templating/init.mdx +58 -0
  302. package/docs/runtime/toml.mdx +238 -0
  303. package/docs/runtime/transpiler.mdx +288 -0
  304. package/docs/runtime/typescript.mdx +58 -0
  305. package/docs/runtime/utils.mdx +1010 -0
  306. package/docs/runtime/watch-mode.mdx +161 -0
  307. package/docs/runtime/web-apis.mdx +29 -0
  308. package/docs/runtime/workers.mdx +314 -0
  309. package/docs/runtime/yaml.mdx +470 -0
  310. package/docs/snippets/cli/add.mdx +166 -0
  311. package/docs/snippets/cli/build.mdx +197 -0
  312. package/docs/snippets/cli/bunx.mdx +49 -0
  313. package/docs/snippets/cli/feedback.mdx +17 -0
  314. package/docs/snippets/cli/init.mdx +84 -0
  315. package/docs/snippets/cli/install.mdx +173 -0
  316. package/docs/snippets/cli/link.mdx +163 -0
  317. package/docs/snippets/cli/outdated.mdx +140 -0
  318. package/docs/snippets/cli/patch.mdx +171 -0
  319. package/docs/snippets/cli/publish.mdx +198 -0
  320. package/docs/snippets/cli/remove.mdx +146 -0
  321. package/docs/snippets/cli/run.mdx +305 -0
  322. package/docs/snippets/cli/test.mdx +105 -0
  323. package/docs/snippets/cli/update.mdx +144 -0
  324. package/docs/test/code-coverage.mdx +409 -0
  325. package/docs/test/configuration.mdx +574 -0
  326. package/docs/test/dates-times.mdx +129 -0
  327. package/docs/test/discovery.mdx +90 -0
  328. package/docs/test/dom.mdx +226 -0
  329. package/docs/test/index.mdx +409 -0
  330. package/docs/test/lifecycle.mdx +366 -0
  331. package/docs/test/mocks.mdx +637 -0
  332. package/docs/test/reporters.mdx +126 -0
  333. package/docs/test/runtime-behavior.mdx +342 -0
  334. package/docs/test/snapshots.mdx +434 -0
  335. package/docs/test/writing-tests.mdx +672 -0
  336. package/docs/typescript.mdx +54 -0
  337. package/extensions.d.ts +40 -0
  338. package/fetch.d.ts +79 -0
  339. package/ffi.d.ts +1154 -0
  340. package/globals.d.ts +2067 -0
  341. package/html-rewriter.d.ts +186 -0
  342. package/index.d.ts +32 -0
  343. package/jsc.d.ts +233 -0
  344. package/jsx.d.ts +11 -0
  345. package/overrides.d.ts +376 -0
  346. package/package.json +53 -0
  347. package/redis.d.ts +3352 -0
  348. package/s3.d.ts +1354 -0
  349. package/security.d.ts +101 -0
  350. package/serve.d.ts +1296 -0
  351. package/shell.d.ts +380 -0
  352. package/sql.d.ts +887 -0
  353. package/sqlite.d.ts +1322 -0
  354. package/test-globals.d.ts +22 -0
  355. package/test.d.ts +2392 -0
  356. package/vendor/expect-type/branding.d.ts +283 -0
  357. package/vendor/expect-type/index.d.ts +1207 -0
  358. package/vendor/expect-type/messages.d.ts +395 -0
  359. package/vendor/expect-type/overloads.d.ts +669 -0
  360. package/vendor/expect-type/utils.d.ts +431 -0
  361. package/wasm.d.ts +193 -0
@@ -0,0 +1,672 @@
1
+ ---
2
+ title: "Writing tests"
3
+ description: "Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers"
4
+ ---
5
+
6
+ Define tests with a Jest-like API imported from the built-in `bun:test` module. Long term, Bun aims for complete Jest compatibility; at the moment, a limited set of expect matchers are supported.
7
+
8
+ ## Basic Usage
9
+
10
+ To define a simple test:
11
+
12
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
13
+ import { expect, test } from "bun:test";
14
+
15
+ test("2 + 2", () => {
16
+ expect(2 + 2).toBe(4);
17
+ });
18
+ ```
19
+
20
+ ### Grouping Tests
21
+
22
+ Tests can be grouped into suites with `describe`.
23
+
24
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
25
+ import { expect, test, describe } from "bun:test";
26
+
27
+ describe("arithmetic", () => {
28
+ test("2 + 2", () => {
29
+ expect(2 + 2).toBe(4);
30
+ });
31
+
32
+ test("2 * 2", () => {
33
+ expect(2 * 2).toBe(4);
34
+ });
35
+ });
36
+ ```
37
+
38
+ ### Async Tests
39
+
40
+ Tests can be async.
41
+
42
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
43
+ import { expect, test } from "bun:test";
44
+
45
+ test("2 * 2", async () => {
46
+ const result = await Promise.resolve(2 * 2);
47
+ expect(result).toEqual(4);
48
+ });
49
+ ```
50
+
51
+ Alternatively, use the `done` callback to signal completion. If you include the `done` callback as a parameter in your test definition, you must call it or the test will hang.
52
+
53
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
54
+ import { expect, test } from "bun:test";
55
+
56
+ test("2 * 2", done => {
57
+ Promise.resolve(2 * 2).then(result => {
58
+ expect(result).toEqual(4);
59
+ done();
60
+ });
61
+ });
62
+ ```
63
+
64
+ ## Timeouts
65
+
66
+ Optionally specify a per-test timeout in milliseconds by passing a number as the third argument to `test`.
67
+
68
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
69
+ import { test } from "bun:test";
70
+
71
+ test("wat", async () => {
72
+ const data = await slowOperation();
73
+ expect(data).toBe(42);
74
+ }, 500); // test must run in <500ms
75
+ ```
76
+
77
+ In `bun:test`, test timeouts throw an uncatchable exception to force the test to stop running and fail. We also kill any child processes that were spawned in the test to avoid leaving behind zombie processes lurking in the background.
78
+
79
+ The default timeout for each test is 5000ms (5 seconds) if not overridden by this timeout option or `jest.setDefaultTimeout()`.
80
+
81
+ ## Retries and Repeats
82
+
83
+ ### test.retry
84
+
85
+ Use the `retry` option to automatically retry a test if it fails. The test passes if it succeeds within the specified number of attempts. This is useful for flaky tests that may fail intermittently.
86
+
87
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
88
+ import { test } from "bun:test";
89
+
90
+ test(
91
+ "flaky network request",
92
+ async () => {
93
+ const response = await fetch("https://example.com/api");
94
+ expect(response.ok).toBe(true);
95
+ },
96
+ { retry: 3 }, // Retry up to 3 times if the test fails
97
+ );
98
+ ```
99
+
100
+ ### test.repeats
101
+
102
+ Use the `repeats` option to run a test multiple times regardless of pass/fail status. The test fails if any iteration fails. This is useful for detecting flaky tests or stress testing. Note that `repeats: N` runs the test N+1 times total (1 initial run + N repeats).
103
+
104
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
105
+ import { test } from "bun:test";
106
+
107
+ test(
108
+ "ensure test is stable",
109
+ () => {
110
+ expect(Math.random()).toBeLessThan(1);
111
+ },
112
+ { repeats: 20 }, // Runs 21 times total (1 initial + 20 repeats)
113
+ );
114
+ ```
115
+
116
+ <Note>You cannot use both `retry` and `repeats` on the same test.</Note>
117
+
118
+ ### 🧟 Zombie Process Killer
119
+
120
+ When a test times out and processes spawned in the test via `Bun.spawn`, `Bun.spawnSync`, or `node:child_process` are not killed, they will be automatically killed and a message will be logged to the console. This prevents zombie processes from lingering in the background after timed-out tests.
121
+
122
+ ## Test Modifiers
123
+
124
+ ### test.skip
125
+
126
+ Skip individual tests with `test.skip`. These tests will not be run.
127
+
128
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
129
+ import { expect, test } from "bun:test";
130
+
131
+ test.skip("wat", () => {
132
+ // TODO: fix this
133
+ expect(0.1 + 0.2).toEqual(0.3);
134
+ });
135
+ ```
136
+
137
+ ### test.todo
138
+
139
+ Mark a test as a todo with `test.todo`. These tests will not be run.
140
+
141
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
142
+ import { expect, test } from "bun:test";
143
+
144
+ test.todo("fix this", () => {
145
+ myTestFunction();
146
+ });
147
+ ```
148
+
149
+ To run todo tests and find any which are passing, use `bun test --todo`.
150
+
151
+ ```bash terminal icon="terminal"
152
+ bun test --todo
153
+ ```
154
+
155
+ ```
156
+ my.test.ts:
157
+ ✗ unimplemented feature
158
+ ^ this test is marked as todo but passes. Remove `.todo` or check that test is correct.
159
+
160
+ 0 pass
161
+ 1 fail
162
+ 1 expect() calls
163
+ ```
164
+
165
+ With this flag, failing todo tests will not cause an error, but todo tests which pass will be marked as failing so you can remove the todo mark or fix the test.
166
+
167
+ ### test.only
168
+
169
+ To run a particular test or suite of tests use `test.only()` or `describe.only()`.
170
+
171
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
172
+ import { test, describe } from "bun:test";
173
+
174
+ test("test #1", () => {
175
+ // does not run
176
+ });
177
+
178
+ test.only("test #2", () => {
179
+ // runs
180
+ });
181
+
182
+ describe.only("only", () => {
183
+ test("test #3", () => {
184
+ // runs
185
+ });
186
+ });
187
+ ```
188
+
189
+ The following command will only execute tests #2 and #3.
190
+
191
+ ```bash terminal icon="terminal"
192
+ bun test --only
193
+ ```
194
+
195
+ The following command will only execute tests #1, #2 and #3.
196
+
197
+ ```bash terminal icon="terminal"
198
+ bun test
199
+ ```
200
+
201
+ ### test.if
202
+
203
+ To run a test conditionally, use `test.if()`. The test will run if the condition is truthy. This is particularly useful for tests that should only run on specific architectures or operating systems.
204
+
205
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
206
+ test.if(Math.random() > 0.5)("runs half the time", () => {
207
+ // ...
208
+ });
209
+
210
+ const macOS = process.platform === "darwin";
211
+ test.if(macOS)("runs on macOS", () => {
212
+ // runs if macOS
213
+ });
214
+ ```
215
+
216
+ ### test.skipIf
217
+
218
+ To instead skip a test based on some condition, use `test.skipIf()` or `describe.skipIf()`.
219
+
220
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
221
+ const macOS = process.platform === "darwin";
222
+
223
+ test.skipIf(macOS)("runs on non-macOS", () => {
224
+ // runs if *not* macOS
225
+ });
226
+ ```
227
+
228
+ ### test.todoIf
229
+
230
+ If instead you want to mark the test as TODO, use `test.todoIf()` or `describe.todoIf()`. Carefully choosing `skipIf` or `todoIf` can show a difference between, for example, intent of "invalid for this target" and "planned but not implemented yet."
231
+
232
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
233
+ const macOS = process.platform === "darwin";
234
+
235
+ // TODO: we've only implemented this for Linux so far.
236
+ test.todoIf(macOS)("runs on posix", () => {
237
+ // runs if *not* macOS
238
+ });
239
+ ```
240
+
241
+ ### test.failing
242
+
243
+ Use `test.failing()` when you know a test is currently failing but you want to track it and be notified when it starts passing. This inverts the test result:
244
+
245
+ - A failing test marked with `.failing()` will pass
246
+ - A passing test marked with `.failing()` will fail (with a message indicating it's now passing and should be fixed)
247
+
248
+ ```ts math.test.ts icon="/icons/typescript.svg"
249
+ // This will pass because the test is failing as expected
250
+ test.failing("math is broken", () => {
251
+ expect(0.1 + 0.2).toBe(0.3); // fails due to floating point precision
252
+ });
253
+
254
+ // This will fail with a message that the test is now passing
255
+ test.failing("fixed bug", () => {
256
+ expect(1 + 1).toBe(2); // passes, but we expected it to fail
257
+ });
258
+ ```
259
+
260
+ This is useful for tracking known bugs that you plan to fix later, or for implementing test-driven development.
261
+
262
+ ## Conditional Tests for Describe Blocks
263
+
264
+ The conditional modifiers `.if()`, `.skipIf()`, and `.todoIf()` can also be applied to describe blocks, affecting all tests within the suite:
265
+
266
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
267
+ const isMacOS = process.platform === "darwin";
268
+
269
+ // Only runs the entire suite on macOS
270
+ describe.if(isMacOS)("macOS-specific features", () => {
271
+ test("feature A", () => {
272
+ // only runs on macOS
273
+ });
274
+
275
+ test("feature B", () => {
276
+ // only runs on macOS
277
+ });
278
+ });
279
+
280
+ // Skips the entire suite on Windows
281
+ describe.skipIf(process.platform === "win32")("Unix features", () => {
282
+ test("feature C", () => {
283
+ // skipped on Windows
284
+ });
285
+ });
286
+
287
+ // Marks the entire suite as TODO on Linux
288
+ describe.todoIf(process.platform === "linux")("Upcoming Linux support", () => {
289
+ test("feature D", () => {
290
+ // marked as TODO on Linux
291
+ });
292
+ });
293
+ ```
294
+
295
+ ## Parametrized Tests
296
+
297
+ ### `test.each` and `describe.each`
298
+
299
+ To run the same test with multiple sets of data, use `test.each`. This creates a parametrized test that runs once for each test case provided.
300
+
301
+ ```ts title="math.test.ts" icon="/icons/typescript.svg"
302
+ const cases = [
303
+ [1, 2, 3],
304
+ [3, 4, 7],
305
+ ];
306
+
307
+ test.each(cases)("%p + %p should be %p", (a, b, expected) => {
308
+ expect(a + b).toBe(expected);
309
+ });
310
+ ```
311
+
312
+ You can also use `describe.each` to create a parametrized suite that runs once for each test case:
313
+
314
+ ```ts title="sum.test.ts" icon="/icons/typescript.svg"
315
+ describe.each([
316
+ [1, 2, 3],
317
+ [3, 4, 7],
318
+ ])("add(%i, %i)", (a, b, expected) => {
319
+ test(`returns ${expected}`, () => {
320
+ expect(a + b).toBe(expected);
321
+ });
322
+
323
+ test(`sum is greater than each value`, () => {
324
+ expect(a + b).toBeGreaterThan(a);
325
+ expect(a + b).toBeGreaterThan(b);
326
+ });
327
+ });
328
+ ```
329
+
330
+ ### Argument Passing
331
+
332
+ How arguments are passed to your test function depends on the structure of your test cases:
333
+
334
+ - If a table row is an array (like `[1, 2, 3]`), each element is passed as an individual argument
335
+ - If a row is not an array (like an object), it's passed as a single argument
336
+
337
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
338
+ // Array items passed as individual arguments
339
+ test.each([
340
+ [1, 2, 3],
341
+ [4, 5, 9],
342
+ ])("add(%i, %i) = %i", (a, b, expected) => {
343
+ expect(a + b).toBe(expected);
344
+ });
345
+
346
+ // Object items passed as a single argument
347
+ test.each([
348
+ { a: 1, b: 2, expected: 3 },
349
+ { a: 4, b: 5, expected: 9 },
350
+ ])("add($a, $b) = $expected", data => {
351
+ expect(data.a + data.b).toBe(data.expected);
352
+ });
353
+ ```
354
+
355
+ ### Format Specifiers
356
+
357
+ There are a number of options available for formatting the test title:
358
+
359
+ | Specifier | Description |
360
+ | --------- | ----------------------- |
361
+ | `%p` | pretty-format |
362
+ | `%s` | String |
363
+ | `%d` | Number |
364
+ | `%i` | Integer |
365
+ | `%f` | Floating point |
366
+ | `%j` | JSON |
367
+ | `%o` | Object |
368
+ | `%#` | Index of the test case |
369
+ | `%%` | Single percent sign (%) |
370
+
371
+ #### Examples
372
+
373
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
374
+ // Basic specifiers
375
+ test.each([
376
+ ["hello", 123],
377
+ ["world", 456],
378
+ ])("string: %s, number: %i", (str, num) => {
379
+ // "string: hello, number: 123"
380
+ // "string: world, number: 456"
381
+ });
382
+
383
+ // %p for pretty-format output
384
+ test.each([
385
+ [{ name: "Alice" }, { a: 1, b: 2 }],
386
+ [{ name: "Bob" }, { x: 5, y: 10 }],
387
+ ])("user %p with data %p", (user, data) => {
388
+ // "user { name: 'Alice' } with data { a: 1, b: 2 }"
389
+ // "user { name: 'Bob' } with data { x: 5, y: 10 }"
390
+ });
391
+
392
+ // %# for index
393
+ test.each(["apple", "banana"])("fruit #%# is %s", fruit => {
394
+ // "fruit #0 is apple"
395
+ // "fruit #1 is banana"
396
+ });
397
+ ```
398
+
399
+ ## Assertion Counting
400
+
401
+ Bun supports verifying that a specific number of assertions were called during a test:
402
+
403
+ ### expect.hasAssertions()
404
+
405
+ Use `expect.hasAssertions()` to verify that at least one assertion is called during a test:
406
+
407
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
408
+ test("async work calls assertions", async () => {
409
+ expect.hasAssertions(); // Will fail if no assertions are called
410
+
411
+ const data = await fetchData();
412
+ expect(data).toBeDefined();
413
+ });
414
+ ```
415
+
416
+ This is especially useful for async tests to ensure your assertions actually run.
417
+
418
+ ### expect.assertions(count)
419
+
420
+ Use `expect.assertions(count)` to verify that a specific number of assertions are called during a test:
421
+
422
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
423
+ test("exactly two assertions", () => {
424
+ expect.assertions(2); // Will fail if not exactly 2 assertions are called
425
+
426
+ expect(1 + 1).toBe(2);
427
+ expect("hello").toContain("ell");
428
+ });
429
+ ```
430
+
431
+ This helps ensure all your assertions run, especially in complex async code with multiple code paths.
432
+
433
+ ## Type Testing
434
+
435
+ Bun includes `expectTypeOf` for testing TypeScript types, compatible with Vitest.
436
+
437
+ ### expectTypeOf
438
+
439
+ <Warning>
440
+ These functions are no-ops at runtime - you need to run TypeScript separately to verify the type checks.
441
+ </Warning>
442
+
443
+ The `expectTypeOf` function provides type-level assertions that are checked by TypeScript's type checker. To test your types:
444
+
445
+ 1. Write your type assertions using `expectTypeOf`
446
+ 2. Run `bunx tsc --noEmit` to check that your types are correct
447
+
448
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
449
+ import { expectTypeOf } from "bun:test";
450
+
451
+ // Basic type assertions
452
+ expectTypeOf<string>().toEqualTypeOf<string>();
453
+ expectTypeOf(123).toBeNumber();
454
+ expectTypeOf("hello").toBeString();
455
+
456
+ // Object type matching
457
+ expectTypeOf({ a: 1, b: "hello" }).toMatchObjectType<{ a: number }>();
458
+
459
+ // Function types
460
+ function greet(name: string): string {
461
+ return `Hello ${name}`;
462
+ }
463
+
464
+ expectTypeOf(greet).toBeFunction();
465
+ expectTypeOf(greet).parameters.toEqualTypeOf<[string]>();
466
+ expectTypeOf(greet).returns.toEqualTypeOf<string>();
467
+
468
+ // Array types
469
+ expectTypeOf([1, 2, 3]).items.toBeNumber();
470
+
471
+ // Promise types
472
+ expectTypeOf(Promise.resolve(42)).resolves.toBeNumber();
473
+ ```
474
+
475
+ For full documentation on expectTypeOf matchers, see the [API Reference](https://bun.com/reference/bun/test/expectTypeOf).
476
+
477
+ ## Matchers
478
+
479
+ Bun implements the following matchers. Full Jest compatibility is on the roadmap; [track progress here](https://github.com/oven-sh/bun/issues/1825).
480
+
481
+ ### Basic Matchers
482
+
483
+ | Status | Matcher |
484
+ | ------ | ------------------ |
485
+ | ✅ | `.not` |
486
+ | ✅ | `.toBe()` |
487
+ | ✅ | `.toEqual()` |
488
+ | ✅ | `.toBeNull()` |
489
+ | ✅ | `.toBeUndefined()` |
490
+ | ✅ | `.toBeNaN()` |
491
+ | ✅ | `.toBeDefined()` |
492
+ | ✅ | `.toBeFalsy()` |
493
+ | ✅ | `.toBeTruthy()` |
494
+ | ✅ | `.toStrictEqual()` |
495
+
496
+ ### String and Array Matchers
497
+
498
+ | Status | Matcher |
499
+ | ------ | --------------------- |
500
+ | ✅ | `.toContain()` |
501
+ | ✅ | `.toHaveLength()` |
502
+ | ✅ | `.toMatch()` |
503
+ | ✅ | `.toContainEqual()` |
504
+ | ✅ | `.stringContaining()` |
505
+ | ✅ | `.stringMatching()` |
506
+ | ✅ | `.arrayContaining()` |
507
+
508
+ ### Object Matchers
509
+
510
+ | Status | Matcher |
511
+ | ------ | ----------------------- |
512
+ | ✅ | `.toHaveProperty()` |
513
+ | ✅ | `.toMatchObject()` |
514
+ | ✅ | `.toContainAllKeys()` |
515
+ | ✅ | `.toContainValue()` |
516
+ | ✅ | `.toContainValues()` |
517
+ | ✅ | `.toContainAllValues()` |
518
+ | ✅ | `.toContainAnyValues()` |
519
+ | ✅ | `.objectContaining()` |
520
+
521
+ ### Number Matchers
522
+
523
+ | Status | Matcher |
524
+ | ------ | --------------------------- |
525
+ | ✅ | `.toBeCloseTo()` |
526
+ | ✅ | `.closeTo()` |
527
+ | ✅ | `.toBeGreaterThan()` |
528
+ | ✅ | `.toBeGreaterThanOrEqual()` |
529
+ | ✅ | `.toBeLessThan()` |
530
+ | ✅ | `.toBeLessThanOrEqual()` |
531
+
532
+ ### Function and Class Matchers
533
+
534
+ | Status | Matcher |
535
+ | ------ | ------------------- |
536
+ | ✅ | `.toThrow()` |
537
+ | ✅ | `.toBeInstanceOf()` |
538
+
539
+ ### Promise Matchers
540
+
541
+ | Status | Matcher |
542
+ | ------ | ------------- |
543
+ | ✅ | `.resolves()` |
544
+ | ✅ | `.rejects()` |
545
+
546
+ ### Mock Function Matchers
547
+
548
+ | Status | Matcher |
549
+ | ------ | ----------------------------- |
550
+ | ✅ | `.toHaveBeenCalled()` |
551
+ | ✅ | `.toHaveBeenCalledTimes()` |
552
+ | ✅ | `.toHaveBeenCalledWith()` |
553
+ | ✅ | `.toHaveBeenLastCalledWith()` |
554
+ | ✅ | `.toHaveBeenNthCalledWith()` |
555
+ | ✅ | `.toHaveReturned()` |
556
+ | ✅ | `.toHaveReturnedTimes()` |
557
+ | ✅ | `.toHaveReturnedWith()` |
558
+ | ✅ | `.toHaveLastReturnedWith()` |
559
+ | ✅ | `.toHaveNthReturnedWith()` |
560
+
561
+ ### Snapshot Matchers
562
+
563
+ | Status | Matcher |
564
+ | ------ | --------------------------------------- |
565
+ | ✅ | `.toMatchSnapshot()` |
566
+ | ✅ | `.toMatchInlineSnapshot()` |
567
+ | ✅ | `.toThrowErrorMatchingSnapshot()` |
568
+ | ✅ | `.toThrowErrorMatchingInlineSnapshot()` |
569
+
570
+ ### Utility Matchers
571
+
572
+ | Status | Matcher |
573
+ | ------ | ------------------ |
574
+ | ✅ | `.extend` |
575
+ | ✅ | `.anything()` |
576
+ | ✅ | `.any()` |
577
+ | ✅ | `.assertions()` |
578
+ | ✅ | `.hasAssertions()` |
579
+
580
+ ### Not Yet Implemented
581
+
582
+ | Status | Matcher |
583
+ | ------ | -------------------------- |
584
+ | ❌ | `.addSnapshotSerializer()` |
585
+
586
+ ## Best Practices
587
+
588
+ ### Use Descriptive Test Names
589
+
590
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
591
+ // Good
592
+ test("should calculate total price including tax for multiple items", () => {
593
+ // test implementation
594
+ });
595
+
596
+ // Avoid
597
+ test("price calculation", () => {
598
+ // test implementation
599
+ });
600
+ ```
601
+
602
+ ### Group Related Tests
603
+
604
+ ```ts title="auth.test.ts" icon="/icons/typescript.svg"
605
+ describe("User authentication", () => {
606
+ describe("with valid credentials", () => {
607
+ test("should return user data", () => {
608
+ // test implementation
609
+ });
610
+
611
+ test("should set authentication token", () => {
612
+ // test implementation
613
+ });
614
+ });
615
+
616
+ describe("with invalid credentials", () => {
617
+ test("should throw authentication error", () => {
618
+ // test implementation
619
+ });
620
+ });
621
+ });
622
+ ```
623
+
624
+ ### Use Appropriate Matchers
625
+
626
+ ```ts title="auth.test.ts" icon="/icons/typescript.svg"
627
+ // Good: Use specific matchers
628
+ expect(users).toHaveLength(3);
629
+ expect(user.email).toContain("@");
630
+ expect(response.status).toBeGreaterThanOrEqual(200);
631
+
632
+ // Avoid: Using toBe for everything
633
+ expect(users.length === 3).toBe(true);
634
+ expect(user.email.includes("@")).toBe(true);
635
+ expect(response.status >= 200).toBe(true);
636
+ ```
637
+
638
+ ### Test Error Conditions
639
+
640
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
641
+ test("should throw error for invalid input", () => {
642
+ expect(() => {
643
+ validateEmail("not-an-email");
644
+ }).toThrow("Invalid email format");
645
+ });
646
+
647
+ test("should handle async errors", async () => {
648
+ await expect(async () => {
649
+ await fetchUser("invalid-id");
650
+ }).rejects.toThrow("User not found");
651
+ });
652
+ ```
653
+
654
+ ### Use Setup and Teardown
655
+
656
+ ```ts title="example.test.ts" icon="/icons/typescript.svg"
657
+ import { beforeEach, afterEach, test } from "bun:test";
658
+
659
+ let testUser;
660
+
661
+ beforeEach(() => {
662
+ testUser = createTestUser();
663
+ });
664
+
665
+ afterEach(() => {
666
+ cleanupTestUser(testUser);
667
+ });
668
+
669
+ test("should update user profile", () => {
670
+ // Use testUser in test
671
+ });
672
+ ```