Skip to content

Commit 8fdb90c

Browse files
committed
Refactor code-style
1 parent 5bd9e6a commit 8fdb90c

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

lib/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ import {convertElement} from 'hast-util-is-element'
1010
*
1111
* The elements `script` and `template` are script-supporting.
1212
*/
13-
export const scriptSupporting = convertElement(['script', 'template'])
13+
export const scriptSupporting = convertElement(
14+
/**
15+
* @param element
16+
* @returns {element is import('hast').Element & {tagName: 'script' | 'template'}}}
17+
*/
18+
function (element) {
19+
return element.tagName === 'script' || element.tagName === 'template'
20+
}
21+
)

test.js

+48-38
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
import assert from 'node:assert/strict'
22
import test from 'node:test'
33
import {scriptSupporting} from './index.js'
4-
import * as mod from './index.js'
54

6-
test('scriptSupporting', () => {
7-
assert.deepEqual(
8-
Object.keys(mod).sort(),
9-
['scriptSupporting'],
10-
'should expose the public api'
11-
)
5+
test('scriptSupporting', async function (t) {
6+
await t.test('should expose the public api', async function () {
7+
assert.deepEqual(Object.keys(await import('./index.js')).sort(), [
8+
'scriptSupporting'
9+
])
10+
})
1211

13-
assert.equal(scriptSupporting(), false, 'should return `false` without node')
12+
await t.test('should return `false` without node', async function () {
13+
// @ts-expect-error `node` should be given.
14+
assert.equal(scriptSupporting(), false)
15+
})
1416

15-
assert.equal(
16-
scriptSupporting(null),
17-
false,
18-
'should return `false` with `null`'
19-
)
17+
await t.test('should return `false` with `null`', async function () {
18+
assert.equal(scriptSupporting(null), false)
19+
})
2020

21-
assert.equal(
22-
scriptSupporting({type: 'text'}),
23-
false,
24-
'should return `false` when without `element`'
21+
await t.test(
22+
'should return `false` when without `element`',
23+
async function () {
24+
assert.equal(scriptSupporting({type: 'text'}), false)
25+
}
2526
)
2627

27-
assert.equal(
28-
scriptSupporting({type: 'element'}),
29-
false,
30-
'should return `false` when with invalid `element`'
28+
await t.test(
29+
'should return `false` when with invalid `element`',
30+
async function () {
31+
assert.equal(scriptSupporting({type: 'element'}), false)
32+
}
3133
)
3234

33-
assert.equal(
34-
scriptSupporting({
35-
type: 'element',
36-
tagName: 'a',
37-
properties: {href: '#alpha', title: 'Bravo'},
38-
children: [{type: 'text', value: 'Charlie'}]
39-
}),
40-
false,
41-
'should return `false` when without not script-supporting'
35+
await t.test(
36+
'should return `false` when without not script-supporting',
37+
async function () {
38+
assert.equal(
39+
scriptSupporting({
40+
type: 'element',
41+
tagName: 'a',
42+
properties: {href: '#alpha', title: 'Bravo'},
43+
children: [{type: 'text', value: 'Charlie'}]
44+
}),
45+
false
46+
)
47+
}
4248
)
4349

44-
assert.equal(
45-
scriptSupporting({
46-
type: 'element',
47-
tagName: 'template',
48-
children: [{type: 'text', value: 'Delta'}]
49-
}),
50-
true,
51-
'should return `true` when with script-supporting'
50+
await t.test(
51+
'should return `true` when with script-supporting',
52+
async function () {
53+
assert.equal(
54+
scriptSupporting({
55+
type: 'element',
56+
tagName: 'template',
57+
children: [{type: 'text', value: 'Delta'}]
58+
}),
59+
true
60+
)
61+
}
5262
)
5363
})

0 commit comments

Comments
 (0)