|
1 | 1 | import assert from 'node:assert/strict'
|
2 | 2 | import test from 'node:test'
|
3 |
| -import {u} from 'unist-builder' |
4 | 3 | import {h} from 'hastscript'
|
| 4 | +import {u} from 'unist-builder' |
5 | 5 | import {classnames} from './index.js'
|
6 |
| -import * as mod from './index.js' |
7 | 6 |
|
8 |
| -test('classnames', () => { |
9 |
| - assert.deepEqual( |
10 |
| - Object.keys(mod).sort(), |
11 |
| - ['classnames'], |
12 |
| - 'should expose the public api' |
13 |
| - ) |
| 7 | +test('classnames', async function (t) { |
| 8 | + await t.test('should expose the public api', async function () { |
| 9 | + assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ |
| 10 | + 'classnames' |
| 11 | + ]) |
| 12 | + }) |
14 | 13 |
|
15 |
| - assert.throws( |
16 |
| - () => { |
| 14 | + await t.test('should ignore a given doctype', async function () { |
| 15 | + assert.throws(function () { |
17 | 16 | classnames(u('comment', '?'))
|
18 |
| - }, |
19 |
| - /Expected element node/, |
20 |
| - 'should ignore a given doctype' |
21 |
| - ) |
| 17 | + }, /Expected element node/) |
| 18 | + }) |
22 | 19 |
|
23 |
| - assert.deepEqual( |
24 |
| - classnames(h('a'), 'alpha'), |
25 |
| - h('a.alpha'), |
26 |
| - 'should support a string' |
27 |
| - ) |
| 20 | + await t.test('should support a string', async function () { |
| 21 | + assert.deepEqual(classnames(h('a'), 'alpha'), h('a.alpha')) |
| 22 | + }) |
28 | 23 |
|
29 |
| - assert.deepEqual( |
30 |
| - classnames(h('a'), 'alpha bravo charlie'), |
31 |
| - h('a.alpha.bravo.charlie'), |
32 |
| - 'should support a string (space-separated)' |
33 |
| - ) |
| 24 | + await t.test('should support a string (space-separated)', async function () { |
| 25 | + assert.deepEqual( |
| 26 | + classnames(h('a'), 'alpha bravo charlie'), |
| 27 | + h('a.alpha.bravo.charlie') |
| 28 | + ) |
| 29 | + }) |
34 | 30 |
|
35 |
| - assert.deepEqual( |
36 |
| - classnames(h('a'), 123), |
37 |
| - h('a.123'), |
38 |
| - 'should support a number' |
39 |
| - ) |
| 31 | + await t.test('should support a number', async function () { |
| 32 | + assert.deepEqual(classnames(h('a'), 123), h('a.123')) |
| 33 | + }) |
40 | 34 |
|
41 |
| - assert.deepEqual( |
42 |
| - classnames(h('a'), null, undefined, 2), |
43 |
| - h('a.2'), |
44 |
| - 'should support (ignore) nullish values' |
45 |
| - ) |
| 35 | + await t.test('should support (ignore) nullish values', async function () { |
| 36 | + assert.deepEqual(classnames(h('a'), null, undefined, 2), h('a.2')) |
| 37 | + }) |
46 | 38 |
|
47 |
| - assert.deepEqual( |
48 |
| - classnames(h('a'), {alpha: true, bravo: false, charlie: true}), |
49 |
| - h('a.alpha.charlie'), |
50 |
| - 'should support an object' |
51 |
| - ) |
| 39 | + await t.test('should support an object', async function () { |
| 40 | + assert.deepEqual( |
| 41 | + classnames(h('a'), {alpha: true, bravo: false, charlie: true}), |
| 42 | + h('a.alpha.charlie') |
| 43 | + ) |
| 44 | + }) |
52 | 45 |
|
53 |
| - assert.deepEqual( |
54 |
| - classnames(h('a'), [ |
55 |
| - 'alpha', |
56 |
| - {bravo: true, charlie: false}, |
57 |
| - ['delta', 123] |
58 |
| - ]), |
59 |
| - h('a.123.alpha.bravo.delta'), |
60 |
| - 'should support an array' |
61 |
| - ) |
| 46 | + await t.test('should support an array', async function () { |
| 47 | + assert.deepEqual( |
| 48 | + classnames(h('a'), [ |
| 49 | + 'alpha', |
| 50 | + {bravo: true, charlie: false}, |
| 51 | + ['delta', 123] |
| 52 | + ]), |
| 53 | + h('a.alpha.bravo.delta.123') |
| 54 | + ) |
| 55 | + }) |
62 | 56 |
|
63 |
| - assert.deepEqual( |
64 |
| - classnames(h('a'), ['alpha', 'bravo', {alpha: false, charlie: true}]), |
65 |
| - h('a.bravo.charlie'), |
66 |
| - 'should dedupe' |
67 |
| - ) |
| 57 | + await t.test('should dedupe', async function () { |
| 58 | + assert.deepEqual( |
| 59 | + classnames(h('a'), ['alpha', 'bravo', {alpha: false, charlie: true}]), |
| 60 | + h('a.bravo.charlie') |
| 61 | + ) |
| 62 | + }) |
68 | 63 |
|
69 |
| - assert.deepEqual( |
70 |
| - classnames(h('a.alpha.bravo'), ['alpha', {alpha: true}]), |
71 |
| - h('a.alpha.bravo'), |
72 |
| - 'should merge w/ current classnames' |
73 |
| - ) |
| 64 | + await t.test('should merge w/ current classnames', async function () { |
| 65 | + assert.deepEqual( |
| 66 | + classnames(h('a.alpha.bravo'), ['alpha', {alpha: true}]), |
| 67 | + h('a.alpha.bravo') |
| 68 | + ) |
| 69 | + }) |
74 | 70 |
|
75 |
| - assert.deepEqual( |
76 |
| - classnames(h('a'), 'alpha', {bravo: true, charlie: false}, ['delta', 123]), |
77 |
| - h('a.123.alpha.bravo.delta'), |
78 |
| - 'should support multiple conditionals' |
79 |
| - ) |
| 71 | + await t.test('should support multiple conditionals', async function () { |
| 72 | + assert.deepEqual( |
| 73 | + classnames(h('a'), 'alpha', {bravo: true, charlie: false}, [ |
| 74 | + 'delta', |
| 75 | + 123 |
| 76 | + ]), |
| 77 | + h('a.alpha.bravo.delta.123') |
| 78 | + ) |
| 79 | + }) |
80 | 80 |
|
81 |
| - assert.deepEqual( |
82 |
| - classnames('alpha', ['bravo', 123], {charlie: true}), |
83 |
| - ['123', 'alpha', 'bravo', 'charlie'], |
84 |
| - 'should return a list if w/o element' |
85 |
| - ) |
| 81 | + await t.test('should return a list if w/o element', async function () { |
| 82 | + assert.deepEqual(classnames('alpha', ['bravo', 123], {charlie: true}), [ |
| 83 | + 'alpha', |
| 84 | + 'bravo', |
| 85 | + '123', |
| 86 | + 'charlie' |
| 87 | + ]) |
| 88 | + }) |
86 | 89 | })
|
0 commit comments