Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions implementors/node/assert.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@

import {
ok,
strictEqual,
notStrictEqual,
deepStrictEqual,
throws,
match,
} from "node:assert/strict";

const assert = Object.assign(
(value, message) => ok(value, message),
{
ok: (value, message) => ok(value, message),
strictEqual: (actual, expected, message) =>
strictEqual(actual, expected, message),
notStrictEqual: (actual, expected, message) =>
notStrictEqual(actual, expected, message),
deepStrictEqual: (actual, expected, message) =>
deepStrictEqual(actual, expected, message),
throws: (fn, error, message) => throws(fn, error, message),
},
);
const assert = Object.assign((value, message) => ok(value, message), {
ok: (value, message) => ok(value, message),
strictEqual: (actual, expected, message) =>
strictEqual(actual, expected, message),
notStrictEqual: (actual, expected, message) =>
notStrictEqual(actual, expected, message),
deepStrictEqual: (actual, expected, message) =>
deepStrictEqual(actual, expected, message),
throws: (fn, error, message) => throws(fn, error, message),
match: (string, regex, message) => match(string, regex, message),
});

Object.assign(globalThis, { assert });
16 changes: 16 additions & 0 deletions tests/harness/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,19 @@ assert.throws(
threw = false;
try { assert.throws(() => { /* does not throw */ }); } catch { threw = true; }
if (!threw) throw new Error('assert.throws must throw when fn does not throw');

// assert.match
if (typeof assert.match !== 'function') {
throw new Error('Expected assert.match to be a function');
}
assert.match('hello world', /hello/);
assert.match('abc123', /^[a-z]+\d+$/);
threw = false;
try { assert.match('hello', /world/); } catch { threw = true; }
if (!threw) throw new Error('assert.match("hello", /world/) must throw');
threw = false;
try { assert.match(123, /\d+/); } catch { threw = true; }
if (!threw) throw new Error('assert.match must throw when input is not a string');
threw = false;
try { assert.match('hello', 'hello'); } catch { threw = true; }
if (!threw) throw new Error('assert.match must throw when pattern is not a RegExp');
Loading