3
3
* @typedef {import('hast').Element } Element
4
4
*/
5
5
6
- import test from 'tape'
6
+ import assert from 'node:assert/strict'
7
+ import test from 'node:test'
7
8
import { isElement } from './index.js'
8
9
9
- test ( 'isElement' , ( t ) => {
10
- t . equal ( isElement ( ) , false , 'should return `false` without node' )
11
- t . equal ( isElement ( null ) , false , 'should return `false` with `null`' )
10
+ test ( 'isElement' , async ( t ) => {
11
+ assert . equal ( isElement ( ) , false , 'should return `false` without node' )
12
+ assert . equal ( isElement ( null ) , false , 'should return `false` with `null`' )
12
13
13
- t . throws (
14
+ assert . throws (
14
15
( ) => {
15
16
// @ts -expect-error runtime.
16
17
isElement ( null , true )
@@ -19,100 +20,94 @@ test('isElement', (t) => {
19
20
'should throw when the second parameter is invalid'
20
21
)
21
22
22
- t . test ( 'isElement(node)' , ( st ) => {
23
- st . equal (
23
+ await t . test ( 'isElement(node)' , ( ) => {
24
+ assert . equal (
24
25
isElement ( { type : 'text' } ) ,
25
26
false ,
26
27
'should return `false` when without `element`'
27
28
)
28
29
29
- st . equal (
30
+ assert . equal (
30
31
isElement ( { type : 'element' } ) ,
31
32
false ,
32
33
'should return `false` when with invalid `element`'
33
34
)
34
35
35
- st . equal (
36
+ assert . equal (
36
37
isElement ( { type : 'element' , tagName : 'div' } ) ,
37
38
true ,
38
39
'should return `true` when with valid `element`'
39
40
)
40
-
41
- st . end ( )
42
41
} )
43
42
44
- t . test ( 'isElement(node, tagName)' , ( st ) => {
45
- st . equal (
43
+ await t . test ( 'isElement(node, tagName)' , ( ) => {
44
+ assert . equal (
46
45
isElement ( { type : 'text' } , 'div' ) ,
47
46
false ,
48
47
'should return `false` when without `element`'
49
48
)
50
49
51
- st . equal (
50
+ assert . equal (
52
51
isElement ( { type : 'element' } , 'div' ) ,
53
52
false ,
54
53
'should return `false` when with invalid `element`'
55
54
)
56
55
57
- st . equal (
56
+ assert . equal (
58
57
isElement ( { type : 'element' , tagName : 'strong' } , 'div' ) ,
59
58
false ,
60
59
'should return `false` when without matching `element`'
61
60
)
62
61
63
- st . equal (
62
+ assert . equal (
64
63
isElement ( { type : 'element' , tagName : 'div' } , 'div' ) ,
65
64
true ,
66
65
'should return `true` when with matching `element`'
67
66
)
68
-
69
- st . end ( )
70
67
} )
71
68
72
- t . test ( 'isElement(node, tagNames)' , ( st ) => {
73
- st . equal (
69
+ await t . test ( 'isElement(node, tagNames)' , ( ) => {
70
+ assert . equal (
74
71
isElement ( { type : 'text' } , [ 'div' ] ) ,
75
72
false ,
76
73
'should return `false` when without `element`'
77
74
)
78
75
79
- st . equal (
76
+ assert . equal (
80
77
isElement ( { type : 'element' } , [ 'div' ] ) ,
81
78
false ,
82
79
'should return `false` when with invalid `element`'
83
80
)
84
81
85
- st . equal (
82
+ assert . equal (
86
83
isElement ( { type : 'element' , tagName : 'strong' } , [ 'div' ] ) ,
87
84
false ,
88
85
'should return `false` when without matching `element`'
89
86
)
90
87
91
- st . equal (
88
+ assert . equal (
92
89
isElement ( { type : 'element' , tagName : 'div' } , [ 'div' , 'strong' , 'em' ] ) ,
93
90
true ,
94
91
'should return `true` when with matching `element` (#1)'
95
92
)
96
93
97
- st . equal (
94
+ assert . equal (
98
95
isElement ( { type : 'element' , tagName : 'em' } , [ 'div' , 'strong' , 'em' ] ) ,
99
96
true ,
100
97
'should return `true` when with matching `element` (#2)'
101
98
)
102
-
103
- st . end ( )
104
99
} )
105
100
106
- t . test ( 'isElement(node, test)' , ( st ) => {
107
- st . equal (
101
+ await t . test ( 'isElement(node, test)' , ( ) => {
102
+ assert . equal (
108
103
isElement ( { type : 'text' } , ( ) => {
109
104
throw new Error ( '!' )
110
105
} ) ,
111
106
false ,
112
107
'should not call `test` if the given node is not an element'
113
108
)
114
109
115
- st . equal (
110
+ assert . equal (
116
111
isElement (
117
112
{ type : 'element' , tagName : 'a' , children : [ ] } ,
118
113
( node ) => node . children . length === 0
@@ -121,7 +116,7 @@ test('isElement', (t) => {
121
116
'should call `test` if the given node is a valid element (1)'
122
117
)
123
118
124
- st . equal (
119
+ assert . equal (
125
120
isElement (
126
121
{ type : 'element' , tagName : 'a' , children : [ { type : 'text' } ] } ,
127
122
( node ) => node . children . length === 0
@@ -136,7 +131,7 @@ test('isElement', (t) => {
136
131
children : [ { type : 'element' , tagName : 'a' , children : [ ] } ]
137
132
}
138
133
139
- st . equal (
134
+ assert . equal (
140
135
isElement (
141
136
root . children [ 0 ] ,
142
137
/**
@@ -146,10 +141,10 @@ test('isElement', (t) => {
146
141
* @param {Parent|undefined|null } parent
147
142
*/
148
143
function ( node , index , parent ) {
149
- st . equal ( node , root . children [ 0 ] , 'should pass `node` to test' )
150
- st . equal ( index , 0 , 'should pass `index` to test' )
151
- st . equal ( parent , root , 'should pass `parent` to test' )
152
- st . equal ( this , ctx , 'should pass `context` to test' )
144
+ assert . equal ( node , root . children [ 0 ] , 'should pass `node` to test' )
145
+ assert . equal ( index , 0 , 'should pass `index` to test' )
146
+ assert . equal ( parent , root , 'should pass `parent` to test' )
147
+ assert . equal ( this , ctx , 'should pass `context` to test' )
153
148
} ,
154
149
0 ,
155
150
root ,
@@ -159,23 +154,23 @@ test('isElement', (t) => {
159
154
'should call `test` if the given node is a valid element (2)'
160
155
)
161
156
162
- st . throws (
157
+ assert . throws (
163
158
( ) => {
164
159
isElement ( root . children [ 0 ] , ( ) => { } , 0 )
165
160
} ,
166
161
/ E x p e c t e d b o t h p a r e n t a n d i n d e x / ,
167
162
'should throw if `index` is passed but not `parent`'
168
163
)
169
164
170
- st . throws (
165
+ assert . throws (
171
166
( ) => {
172
167
isElement ( root . children [ 0 ] , ( ) => { } , undefined , root )
173
168
} ,
174
169
/ E x p e c t e d b o t h p a r e n t a n d i n d e x / ,
175
170
'should throw if `parent` is passed but not `index`'
176
171
)
177
172
178
- st . throws (
173
+ assert . throws (
179
174
( ) => {
180
175
// @ts -expect-error runtime.
181
176
isElement ( root . children [ 0 ] , ( ) => { } , false )
@@ -184,23 +179,23 @@ test('isElement', (t) => {
184
179
'should throw if `index` is not a number'
185
180
)
186
181
187
- st . throws (
182
+ assert . throws (
188
183
( ) => {
189
184
isElement ( root . children [ 0 ] , ( ) => { } , - 1 )
190
185
} ,
191
186
/ E x p e c t e d p o s i t i v e f i n i t e i n d e x f o r c h i l d n o d e / ,
192
187
'should throw if `index` is negative'
193
188
)
194
189
195
- st . throws (
190
+ assert . throws (
196
191
( ) => {
197
192
isElement ( root . children [ 0 ] , ( ) => { } , Number . POSITIVE_INFINITY )
198
193
} ,
199
194
/ E x p e c t e d p o s i t i v e f i n i t e i n d e x f o r c h i l d n o d e / ,
200
195
'should throw if `index` is infinity'
201
196
)
202
197
203
- st . throws (
198
+ assert . throws (
204
199
( ) => {
205
200
// @ts -expect-error runtime.
206
201
isElement ( root . children [ 0 ] , ( ) => { } , 0 , true )
@@ -209,17 +204,13 @@ test('isElement', (t) => {
209
204
'should throw if `parent` is not a node'
210
205
)
211
206
212
- st . throws (
207
+ assert . throws (
213
208
( ) => {
214
209
// @ts -expect-error runtime.
215
210
isElement ( root . children [ 0 ] , ( ) => { } , 0 , { type : 'root' } )
216
211
} ,
217
212
/ E x p e c t e d p a r e n t n o d e / ,
218
213
'should throw if `parent` is not a parent'
219
214
)
220
-
221
- st . end ( )
222
215
} )
223
-
224
- t . end ( )
225
216
} )
0 commit comments