Skip to main content

max / makenotwork

973 B · 24 lines History Blame Raw
1 import { test } from 'node:test';
2 import assert from 'node:assert/strict';
3 import { collectArgs } from './dispatch.ts';
4
5 // A minimal Element stub exposing just getAttribute — enough for collectArgs.
6 const el = (attrs: Record<string, string>) =>
7 ({ getAttribute: (k: string) => (k in attrs ? attrs[k] : null) }) as unknown as Element;
8
9 test('collectArgs reads data-arg then data-arg2 in order', () => {
10 assert.deepEqual(collectArgs(el({ 'data-arg': 'x', 'data-arg2': 'y' })), ['x', 'y']);
11 });
12
13 test('collectArgs stops at the first absent arg slot but keeps a present arg2? no — arg only', () => {
14 assert.deepEqual(collectArgs(el({ 'data-arg': 'only' })), ['only']);
15 });
16
17 test('collectArgs returns empty when neither is present', () => {
18 assert.deepEqual(collectArgs(el({})), []);
19 });
20
21 test('collectArgs preserves empty-string args (attribute present but blank)', () => {
22 assert.deepEqual(collectArgs(el({ 'data-arg': '', 'data-arg2': 'b' })), ['', 'b']);
23 });
24