|
| 1 | +/** |
| 2 | + * @typedef {import('hast').Nodes} Nodes |
| 3 | + */ |
| 4 | + |
1 | 5 | import assert from 'node:assert/strict' |
2 | 6 | import test from 'node:test' |
3 | 7 | import {fromString} from './index.js' |
4 | 8 |
|
5 | 9 | test('hast-util-from-string', async function (t) { |
6 | 10 | await t.test('should set text nodes', async function () { |
7 | | - assert.deepEqual(fromString({type: 'text', value: 'alpha'}, 'bravo'), { |
8 | | - type: 'text', |
9 | | - value: 'bravo' |
10 | | - }) |
| 11 | + /** @type {Nodes} */ |
| 12 | + const node = {type: 'text', value: 'alpha'} |
| 13 | + fromString(node, 'bravo') |
| 14 | + assert.deepEqual(node, {type: 'text', value: 'bravo'}) |
11 | 15 | }) |
12 | 16 |
|
13 | 17 | await t.test('should reset text nodes', async function () { |
14 | | - assert.deepEqual(fromString({type: 'text', value: 'alpha'}), { |
15 | | - type: 'text', |
16 | | - value: '' |
17 | | - }) |
| 18 | + /** @type {Nodes} */ |
| 19 | + const node = {type: 'text', value: 'alpha'} |
| 20 | + fromString(node) |
| 21 | + assert.deepEqual(node, {type: 'text', value: ''}) |
18 | 22 | }) |
19 | 23 |
|
20 | 24 | await t.test('should set parent nodes', async function () { |
21 | | - assert.deepEqual( |
22 | | - fromString( |
23 | | - { |
24 | | - type: 'element', |
25 | | - tagName: 'p', |
26 | | - properties: {}, |
27 | | - children: [{type: 'text', value: 'alpha'}] |
28 | | - }, |
29 | | - 'bravo' |
30 | | - ), |
31 | | - { |
32 | | - type: 'element', |
33 | | - tagName: 'p', |
34 | | - properties: {}, |
35 | | - children: [{type: 'text', value: 'bravo'}] |
36 | | - } |
37 | | - ) |
| 25 | + /** @type {Nodes} */ |
| 26 | + const node = { |
| 27 | + type: 'element', |
| 28 | + tagName: 'p', |
| 29 | + properties: {}, |
| 30 | + children: [{type: 'text', value: 'alpha'}] |
| 31 | + } |
| 32 | + fromString(node, 'bravo') |
| 33 | + |
| 34 | + assert.deepEqual(node, { |
| 35 | + type: 'element', |
| 36 | + tagName: 'p', |
| 37 | + properties: {}, |
| 38 | + children: [{type: 'text', value: 'bravo'}] |
| 39 | + }) |
38 | 40 | }) |
39 | 41 |
|
40 | 42 | await t.test('should reset parent nodes', async function () { |
41 | | - assert.deepEqual( |
42 | | - fromString({ |
43 | | - type: 'element', |
44 | | - tagName: 'p', |
45 | | - properties: {}, |
46 | | - children: [{type: 'text', value: 'alpha'}] |
47 | | - }), |
48 | | - { |
49 | | - type: 'element', |
50 | | - tagName: 'p', |
51 | | - properties: {}, |
52 | | - children: [] |
53 | | - } |
54 | | - ) |
| 43 | + /** @type {Nodes} */ |
| 44 | + const node = { |
| 45 | + type: 'element', |
| 46 | + tagName: 'p', |
| 47 | + properties: {}, |
| 48 | + children: [{type: 'text', value: 'alpha'}] |
| 49 | + } |
| 50 | + fromString(node) |
| 51 | + |
| 52 | + assert.deepEqual(node, { |
| 53 | + type: 'element', |
| 54 | + tagName: 'p', |
| 55 | + properties: {}, |
| 56 | + children: [] |
| 57 | + }) |
55 | 58 | }) |
56 | 59 | }) |
0 commit comments