Skip to content

Commit fdda004

Browse files
committed
Refactor tests to use toHaveLength
1 parent f6dae84 commit fdda004

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

src/__tests__/vue-vnode-utils.spec.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function toVNode(node: VNodeChild): VNode {
7777
}
7878

7979
function compareChildren(vnodes: VNodeArrayChildren, expectation: VNodeArrayChildren) {
80-
expect(vnodes.length).toBe(expectation.length)
80+
expect(vnodes).toHaveLength(expectation.length)
8181

8282
for (let index = 0; index < Math.min(vnodes.length, expectation.length); ++index) {
8383
compareNode(toVNode(vnodes[index]), toVNode(expectation[index]))
@@ -176,15 +176,15 @@ describe('addProps', () => {
176176

177177
expect(count).toBe(1)
178178
expect(Array.isArray(nodes)).toBe(true)
179-
expect(nodes.length).toBe(1)
179+
expect(nodes).toHaveLength(1)
180180

181181
const node = nodes[0] as VNode
182182

183183
expect(isElement(node)).toBe(true)
184184
expect(node.type).toBe('div')
185185
expect(node.props?.class).toBe('red')
186186

187-
expect(startNodes.length).toBe(1)
187+
expect(startNodes).toHaveLength(1)
188188
expect(startNodes[0]).toBe(startNode)
189189
expect(startNode.props).toBe(null)
190190
})
@@ -210,24 +210,24 @@ describe('addProps', () => {
210210

211211
expect(count).toBe(1)
212212
expect(Array.isArray(nodes)).toBe(true)
213-
expect(nodes.length).toBe(1)
213+
expect(nodes).toHaveLength(1)
214214

215215
const node = nodes[0] as VNode
216216

217217
expect(isFragment(node)).toBe(true)
218218
expect(Array.isArray(node.children)).toBe(true)
219-
expect(node.children?.length).toBe(1)
219+
expect(node.children).toHaveLength(1)
220220

221221
const child = (node.children as VNode[])[0]
222222

223223
expect(isElement(child)).toBe(true)
224224
expect(child.type).toBe('div')
225225
expect(child.props?.class).toBe('red')
226226

227-
expect(startNodes.length).toBe(1)
227+
expect(startNodes).toHaveLength(1)
228228
expect(startNodes[0]).toBe(fragNode)
229229
expect(fragNode.props).toBe(null)
230-
expect(fragNode.children?.length).toBe(1)
230+
expect(fragNode.children).toHaveLength(1)
231231
expect((fragNode.children as VNodeArrayChildren)[0]).toBe(divNode)
232232
expect(divNode.props).toBe(null)
233233
})
@@ -261,7 +261,7 @@ describe('addProps', () => {
261261
}
262262
})
263263

264-
expect(calledFor.length).toBe(3)
264+
expect(calledFor).toHaveLength(3)
265265
expect(calledFor.every(node => isVNode(node))).toBe(true)
266266
expect(calledFor[0].type).toBe('div')
267267
expect(calledFor[1].type).toBe('span')
@@ -332,7 +332,7 @@ describe('addProps', () => {
332332
}
333333
})
334334

335-
expect(calledFor.length).toBe(6)
335+
expect(calledFor).toHaveLength(6)
336336
expect(calledFor.every(node => isVNode(node))).toBe(true)
337337
expect(calledFor[0].type).toBe('p')
338338
expect(calledFor[1].type).toMatchObject({ template: 'abc' })
@@ -404,7 +404,7 @@ describe('addProps', () => {
404404

405405
expect(count).toBe(2)
406406

407-
expect(nodes.length).toBe(3)
407+
expect(nodes).toHaveLength(3)
408408
expect((nodes[0] as VNode).props?.class).toBe('red')
409409
expect((nodes[1] as VNode).props?.class).toBe(undefined)
410410

@@ -421,7 +421,7 @@ describe('addProps', () => {
421421

422422
expect(count).toBe(2)
423423

424-
expect(nodes.length).toBe(3)
424+
expect(nodes).toHaveLength(3)
425425
expect((nodes[0] as VNode).props?.class).toBe(undefined)
426426
expect((nodes[1] as VNode).props?.class).toBe('red')
427427
})
@@ -445,10 +445,10 @@ describe('addProps', () => {
445445

446446
expect(count).toBe(2)
447447

448-
expect(nodes.length).toBe(2)
448+
expect(nodes).toHaveLength(2)
449449
expect((nodes[0] as VNode).props?.class).toBe('red')
450450
expect(nodes[1]).toBe(fragment)
451-
expect(fragment.length).toBe(1)
451+
expect(fragment).toHaveLength(1)
452452
expect(fragment[0]).toBe(spanNode)
453453
expect(spanNode.props).toBe(null)
454454
})
@@ -751,7 +751,7 @@ describe('betweenChildren', () => {
751751

752752
expect(count).toBe(1)
753753
expect(Array.isArray(nodes)).toBe(true)
754-
expect(nodes.length).toBe(3)
754+
expect(nodes).toHaveLength(3)
755755

756756
compareChildren(nodes, [h('div'), h('p'), h('span')])
757757
compareChildren(startNodes, [h('div'), h('span')])
@@ -778,7 +778,7 @@ describe('betweenChildren', () => {
778778

779779
expect(count).toBe(1)
780780
expect(Array.isArray(nodes)).toBe(true)
781-
expect(nodes.length).toBe(4)
781+
expect(nodes).toHaveLength(4)
782782

783783
compareChildren(nodes, [h('div'), 'hello', h('strong', null,['world']), h('span')])
784784
compareChildren(startNodes, [h('div'), h('span')])
@@ -814,7 +814,7 @@ describe('betweenChildren', () => {
814814

815815
expect(count).toBe(5)
816816
expect(Array.isArray(nodes)).toBe(true)
817-
expect(nodes.length).toBe(14)
817+
expect(nodes).toHaveLength(14)
818818

819819
compareChildren(startNodes, getStartNodes())
820820

@@ -872,7 +872,7 @@ describe('betweenChildren', () => {
872872

873873
expect(count).toBe(8)
874874
expect(Array.isArray(nodes)).toBe(true)
875-
expect(nodes.length).toBe(17)
875+
expect(nodes).toHaveLength(17)
876876

877877
compareChildren(startNodes, getStartNodes())
878878

@@ -932,7 +932,7 @@ describe('betweenChildren', () => {
932932

933933
expect(count).toBe(1)
934934
expect(Array.isArray(nodes)).toBe(true)
935-
expect(nodes.length).toBe(9)
935+
expect(nodes).toHaveLength(9)
936936

937937
compareChildren(startNodes, getStartNodes())
938938

@@ -983,7 +983,7 @@ describe('betweenChildren', () => {
983983

984984
expect(count).toBe(1)
985985
expect(Array.isArray(nodes)).toBe(true)
986-
expect(nodes.length).toBe(10)
986+
expect(nodes).toHaveLength(10)
987987

988988
compareChildren(startNodes, getStartNodes())
989989

@@ -1038,7 +1038,7 @@ describe('betweenChildren', () => {
10381038

10391039
expect(count).toBe(1)
10401040
expect(Array.isArray(nodes)).toBe(true)
1041-
expect(nodes.length).toBe(10)
1041+
expect(nodes).toHaveLength(10)
10421042

10431043
compareChildren(startNodes, getStartNodes())
10441044

@@ -1090,7 +1090,7 @@ describe('betweenChildren', () => {
10901090

10911091
expect(count).toBe(1)
10921092
expect(Array.isArray(nodes)).toBe(true)
1093-
expect(nodes.length).toBe(10)
1093+
expect(nodes).toHaveLength(10)
10941094

10951095
compareChildren(startNodes, getStartNodes())
10961096

@@ -1139,7 +1139,7 @@ describe('betweenChildren', () => {
11391139

11401140
expect(count).toBe(1)
11411141
expect(Array.isArray(nodes)).toBe(true)
1142-
expect(nodes.length).toBe(3)
1142+
expect(nodes).toHaveLength(3)
11431143

11441144
compareChildren(startNodes, getStartNodes())
11451145

@@ -1188,7 +1188,7 @@ describe('betweenChildren', () => {
11881188

11891189
expect(count).toBe(6)
11901190
expect(Array.isArray(nodes)).toBe(true)
1191-
expect(nodes.length).toBe(2)
1191+
expect(nodes).toHaveLength(2)
11921192

11931193
compareChildren(startNodes, getStartNodes())
11941194

@@ -1293,7 +1293,7 @@ describe('someChild', () => {
12931293
})
12941294

12951295
expect(out).toBe(false)
1296-
expect(calledFor.length).toBe(4)
1296+
expect(calledFor).toHaveLength(4)
12971297
expect(calledFor[0]).toBe(startNodes[0])
12981298
expect(calledFor[1]).toBe((startNodes[1].children as VNode[])[0])
12991299
expect(calledFor[2]).toBe((startNodes[1].children as VNode[])[1])
@@ -1308,7 +1308,7 @@ describe('someChild', () => {
13081308
})
13091309

13101310
expect(out).toBe(true)
1311-
expect(calledFor.length).toBe(3)
1311+
expect(calledFor).toHaveLength(3)
13121312
expect(calledFor[0]).toBe(startNodes[0])
13131313
expect(calledFor[1]).toBe((startNodes[1].children as VNode[])[0])
13141314
expect(calledFor[2]).toBe((startNodes[1].children as VNode[])[1])
@@ -1322,7 +1322,7 @@ describe('someChild', () => {
13221322
})
13231323

13241324
expect(out).toBe(true)
1325-
expect(calledFor.length).toBe(2)
1325+
expect(calledFor).toHaveLength(2)
13261326
expect(calledFor[0]).toBe(startNodes[0])
13271327
expect(calledFor[1]).toBe((startNodes[1].children as VNode[])[0])
13281328
})
@@ -1339,7 +1339,7 @@ describe('someChild', () => {
13391339
return false
13401340
}, ALL_VNODES)
13411341

1342-
expect(calledFor.length).toBe(7)
1342+
expect(calledFor).toHaveLength(7)
13431343

13441344
calledFor.length = 0
13451345

@@ -1349,7 +1349,7 @@ describe('someChild', () => {
13491349
return false
13501350
}, SKIP_COMMENTS)
13511351

1352-
expect(calledFor.length).toBe(6)
1352+
expect(calledFor).toHaveLength(6)
13531353

13541354
calledFor.length = 0
13551355

@@ -1359,7 +1359,7 @@ describe('someChild', () => {
13591359
return false
13601360
}, COMPONENTS_AND_ELEMENTS)
13611361

1362-
expect(calledFor.length).toBe(4)
1362+
expect(calledFor).toHaveLength(4)
13631363

13641364
calledFor.length = 0
13651365

@@ -1369,7 +1369,7 @@ describe('someChild', () => {
13691369
return false
13701370
}, { component: true })
13711371

1372-
expect(calledFor.length).toBe(1)
1372+
expect(calledFor).toHaveLength(1)
13731373

13741374
calledFor.length = 0
13751375

@@ -1379,7 +1379,7 @@ describe('someChild', () => {
13791379
return false
13801380
}, {})
13811381

1382-
expect(calledFor.length).toBe(0)
1382+
expect(calledFor).toHaveLength(0)
13831383

13841384
calledFor.length = 0
13851385

@@ -1389,7 +1389,7 @@ describe('someChild', () => {
13891389
return false
13901390
}, { comment: true })
13911391

1392-
expect(calledFor.length).toBe(1)
1392+
expect(calledFor).toHaveLength(1)
13931393

13941394
calledFor.length = 0
13951395

@@ -1399,7 +1399,7 @@ describe('someChild', () => {
13991399
return false
14001400
}, { text: true })
14011401

1402-
expect(calledFor.length).toBe(2)
1402+
expect(calledFor).toHaveLength(2)
14031403

14041404
calledFor.length = 0
14051405

@@ -1409,7 +1409,7 @@ describe('someChild', () => {
14091409
return false
14101410
}, { element: true })
14111411

1412-
expect(calledFor.length).toBe(3)
1412+
expect(calledFor).toHaveLength(3)
14131413
})
14141414
})
14151415

@@ -1426,7 +1426,7 @@ describe('everyChild', () => {
14261426
})
14271427

14281428
expect(out).toBe(true)
1429-
expect(calledFor.length).toBe(4)
1429+
expect(calledFor).toHaveLength(4)
14301430
expect(calledFor[0].type).toBe('a')
14311431
expect(calledFor[1].type).toBe('div')
14321432
expect(calledFor[2].type).toBe('span')
@@ -1441,7 +1441,7 @@ describe('everyChild', () => {
14411441
})
14421442

14431443
expect(out).toBe(false)
1444-
expect(calledFor.length).toBe(2)
1444+
expect(calledFor).toHaveLength(2)
14451445
expect(calledFor[0].type).toBe('a')
14461446
expect(calledFor[1].type).toBe('div')
14471447
})
@@ -1462,7 +1462,7 @@ describe('eachChild', () => {
14621462
})
14631463

14641464
expect(out).toBe(undefined)
1465-
expect(calledFor.length).toBe(4)
1465+
expect(calledFor).toHaveLength(4)
14661466
expect(calledFor[0]).toBe(startNodes[0])
14671467
expect(isText(calledFor[1]) && getText(calledFor[1])).toBe('Text')
14681468
expect(calledFor[2].type).toBe('span')
@@ -1483,7 +1483,7 @@ describe('findChild', () => {
14831483
})
14841484

14851485
expect(out).toBe(undefined)
1486-
expect(calledFor.length).toBe(4)
1486+
expect(calledFor).toHaveLength(4)
14871487
expect(calledFor[0]).toBe(startNodes[0])
14881488
expect(isText(calledFor[1]) && getText(calledFor[1])).toBe('Text')
14891489
expect(calledFor[2].type).toBe('span')
@@ -1498,7 +1498,7 @@ describe('findChild', () => {
14981498
})
14991499

15001500
expect(out?.type).toBe('span')
1501-
expect(calledFor.length).toBe(3)
1501+
expect(calledFor).toHaveLength(3)
15021502
expect(calledFor[0]).toBe(startNodes[0])
15031503
expect(isText(calledFor[1]) && getText(calledFor[1])).toBe('Text')
15041504
expect(calledFor[2].type).toBe('span')

0 commit comments

Comments
 (0)