6
6
import test from 'tape'
7
7
import { isElement } from './index.js'
8
8
9
- test ( 'isElement' , function ( t ) {
9
+ test ( 'isElement' , ( t ) => {
10
10
t . equal ( isElement ( ) , false , 'should return `false` without node' )
11
11
t . equal ( isElement ( null ) , false , 'should return `false` with `null`' )
12
12
13
13
t . throws (
14
- function ( ) {
14
+ ( ) => {
15
15
// @ts -ignore runtime.
16
16
isElement ( null , true )
17
17
} ,
18
18
/ E x p e c t e d f u n c t i o n , s t r i n g , o r a r r a y a s t e s t / ,
19
19
'should throw when the second parameter is invalid'
20
20
)
21
21
22
- t . test ( 'isElement(node)' , function ( st ) {
22
+ t . test ( 'isElement(node)' , ( st ) => {
23
23
st . equal (
24
24
isElement ( { type : 'text' } ) ,
25
25
false ,
@@ -41,7 +41,7 @@ test('isElement', function (t) {
41
41
st . end ( )
42
42
} )
43
43
44
- t . test ( 'isElement(node, tagName)' , function ( st ) {
44
+ t . test ( 'isElement(node, tagName)' , ( st ) => {
45
45
st . equal (
46
46
isElement ( { type : 'text' } , 'div' ) ,
47
47
false ,
@@ -69,7 +69,7 @@ test('isElement', function (t) {
69
69
st . end ( )
70
70
} )
71
71
72
- t . test ( 'isElement(node, tagNames)' , function ( st ) {
72
+ t . test ( 'isElement(node, tagNames)' , ( st ) => {
73
73
st . equal (
74
74
isElement ( { type : 'text' } , [ 'div' ] ) ,
75
75
false ,
@@ -103,17 +103,17 @@ test('isElement', function (t) {
103
103
st . end ( )
104
104
} )
105
105
106
- t . test ( 'isElement(node, test)' , function ( st ) {
106
+ t . test ( 'isElement(node, test)' , ( st ) => {
107
107
st . equal (
108
- isElement ( { type : 'text' } , function ( ) {
108
+ isElement ( { type : 'text' } , ( ) => {
109
109
throw new Error ( '!' )
110
110
} ) ,
111
111
false ,
112
112
'should not call `test` if the given node is not an element'
113
113
)
114
114
115
115
st . equal (
116
- isElement ( { type : 'element' , tagName : 'a' , children : [ ] } , function ( node ) {
116
+ isElement ( { type : 'element' , tagName : 'a' , children : [ ] } , ( node ) => {
117
117
return node . children . length === 0
118
118
} ) ,
119
119
true ,
@@ -123,16 +123,16 @@ test('isElement', function (t) {
123
123
st . equal (
124
124
isElement (
125
125
{ type : 'element' , tagName : 'a' , children : [ { type : 'text' } ] } ,
126
- function ( node ) {
126
+ ( node ) => {
127
127
return node . children . length === 0
128
128
}
129
129
) ,
130
130
false ,
131
131
'should call `test` if the given node is a valid element (2)'
132
132
)
133
133
134
- var ctx = { }
135
- var root = {
134
+ const ctx = { }
135
+ const root = {
136
136
type : 'root' ,
137
137
children : [ { type : 'element' , tagName : 'a' , children : [ ] } ]
138
138
}
@@ -161,59 +161,59 @@ test('isElement', function (t) {
161
161
)
162
162
163
163
st . throws (
164
- function ( ) {
165
- isElement ( root . children [ 0 ] , function ( ) { } , 0 )
164
+ ( ) => {
165
+ isElement ( root . children [ 0 ] , ( ) => { } , 0 )
166
166
} ,
167
167
/ 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 / ,
168
168
'should throw if `index` is passed but not `parent`'
169
169
)
170
170
171
171
st . throws (
172
- function ( ) {
173
- isElement ( root . children [ 0 ] , function ( ) { } , undefined , root )
172
+ ( ) => {
173
+ isElement ( root . children [ 0 ] , ( ) => { } , undefined , root )
174
174
} ,
175
175
/ 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 / ,
176
176
'should throw if `parent` is passed but not `index`'
177
177
)
178
178
179
179
st . throws (
180
- function ( ) {
180
+ ( ) => {
181
181
// @ts -ignore runtime.
182
- isElement ( root . children [ 0 ] , function ( ) { } , false )
182
+ isElement ( root . children [ 0 ] , ( ) => { } , false )
183
183
} ,
184
184
/ 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 / ,
185
185
'should throw if `index` is not a number'
186
186
)
187
187
188
188
st . throws (
189
- function ( ) {
190
- isElement ( root . children [ 0 ] , function ( ) { } , - 1 )
189
+ ( ) => {
190
+ isElement ( root . children [ 0 ] , ( ) => { } , - 1 )
191
191
} ,
192
192
/ 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 / ,
193
193
'should throw if `index` is negative'
194
194
)
195
195
196
196
st . throws (
197
- function ( ) {
198
- isElement ( root . children [ 0 ] , function ( ) { } , Number . POSITIVE_INFINITY )
197
+ ( ) => {
198
+ isElement ( root . children [ 0 ] , ( ) => { } , Number . POSITIVE_INFINITY )
199
199
} ,
200
200
/ 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 / ,
201
201
'should throw if `index` is infinity'
202
202
)
203
203
204
204
st . throws (
205
- function ( ) {
205
+ ( ) => {
206
206
// @ts -ignore runtime.
207
- isElement ( root . children [ 0 ] , function ( ) { } , 0 , true )
207
+ isElement ( root . children [ 0 ] , ( ) => { } , 0 , true )
208
208
} ,
209
209
/ E x p e c t e d p a r e n t n o d e / ,
210
210
'should throw if `parent` is not a node'
211
211
)
212
212
213
213
st . throws (
214
- function ( ) {
214
+ ( ) => {
215
215
// @ts -ignore runtime.
216
- isElement ( root . children [ 0 ] , function ( ) { } , 0 , { type : 'root' } )
216
+ isElement ( root . children [ 0 ] , ( ) => { } , 0 , { type : 'root' } )
217
217
} ,
218
218
/ E x p e c t e d p a r e n t n o d e / ,
219
219
'should throw if `parent` is not a parent'
0 commit comments