typestar

node:test en JavaScript

El runner viene integrado: una función test y el módulo assert.

import test from "node:test";
import assert from "node:assert/strict";

function slugify(title) {
  return title.trim().toLowerCase().replaceAll(" ", "-");
}

test("joins words with hyphens", () => {
  assert.strictEqual(slugify("Language Basics"), "language-basics");
});

test("trims the edges", () => {
  assert.equal(slugify("  Async  "), "async");
});

test("leaves one word alone", () => {
  assert.ok(!slugify("basics").includes("-"));
});

Cómo funciona

  1. test(name, fn) la registra; el runner reporta cada una.
  2. assert.strictEqual es la comparación por defecto.
  3. Córrelo con node --test o ejecutando el archivo.

Palabras clave y builtins usados aquí

El intento, en números

Líneas
18
Caracteres a escribir
438
Tokens
108
Ritmo de tres estrellas
100 tpm

Al ritmo de tres estrellas de 100 tokens por minuto, este intento toma unos 65 segundos.

Escribe este fragmento

Paso 1 de 2 en Escribir pruebas; paso 1 de 9 en Pruebas con node:test.

Siguiente →