A test that fails for the right reason

Javascript

Assert on the message, not merely that something threw. A typo raising TypeError would otherwise pass.

import { test } from 'node:test';
import assert from 'node:assert/strict';

test('rejects a negative amount', () => {
  assert.throws(
    () => new Money(-1),
    { name: 'RangeError', message: /cannot be negative/ }
  );
});

More in Testing

Random picks