snippettypescriptModeratepending
Deno/Bun native test runner -- zero-config testing
Viewed 0 times
Deno.testbun testnative test runnerzero configassertion
denobunnodejs
Problem
Setting up Jest or Vitest requires configuration, devDependencies, and build tool integration. For small projects, the overhead is not justified.
Solution
Modern runtimes include built-in test runners. Deno and Bun have native test support with zero configuration.
Code Snippets
Native test runners in modern runtimes
// Deno: deno test
import { assertEquals, assertThrows } from 'jsr:@std/assert';
Deno.test('add numbers', () => {
assertEquals(1 + 2, 3);
});
Deno.test('async operation', async () => {
const data = await fetchData();
assertEquals(data.length, 10);
});
// Bun: bun test
import { test, expect, describe } from 'bun:test';
describe('math', () => {
test('adds', () => {
expect(1 + 2).toBe(3);
});
test('throws on invalid', () => {
expect(() => divide(1, 0)).toThrow();
});
});
// Node.js 20+: node --test
import { test, describe } from 'node:test';
import assert from 'node:assert';
test('basic', () => {
assert.strictEqual(1 + 2, 3);
});Revisions (0)
No revisions yet.