1
1
'use strict' ;
2
2
3
- /* eslint-env mocha */
4
-
5
- var assert = require ( 'assert' ) ;
3
+ var test = require ( 'tape' ) ;
6
4
var modifyChildren = require ( './' ) ;
7
5
8
- var throws = assert . throws ;
9
- var equal = assert . strictEqual ;
10
- var deepEqual = assert . deepEqual ;
11
-
12
6
var noop = Function . prototype ;
13
7
14
- describe ( 'modifyChildren()' , function ( ) {
15
- it ( 'should throw when no `parent` is given' , function ( ) {
16
- throws (
17
- function ( ) {
18
- modifyChildren ( noop ) ( ) ;
19
- } ,
20
- / M i s s i n g c h i l d r e n i n ` p a r e n t ` /
21
- ) ;
22
-
23
- throws (
24
- function ( ) {
25
- modifyChildren ( noop ) ( { } ) ;
26
- } ,
27
- / M i s s i n g c h i l d r e n i n ` p a r e n t ` /
28
- ) ;
29
- } ) ;
30
-
31
- it ( 'should invoke `fn` for each child in `parent`' , function ( ) {
8
+ test ( 'modifyChildren()' , function ( t ) {
9
+ t . throws (
10
+ function ( ) {
11
+ modifyChildren ( noop ) ( ) ;
12
+ } ,
13
+ / M i s s i n g c h i l d r e n i n ` p a r e n t ` / ,
14
+ 'should throw without node'
15
+ ) ;
16
+
17
+ t . throws (
18
+ function ( ) {
19
+ modifyChildren ( noop ) ( { } ) ;
20
+ } ,
21
+ / M i s s i n g c h i l d r e n i n ` p a r e n t ` / ,
22
+ 'should throw without parent'
23
+ ) ;
24
+
25
+ t . test ( 'should invoke `fn` for each child in `parent`' , function ( st ) {
32
26
var values = [ 0 , 1 , 2 , 3 ] ;
33
27
var context = { } ;
34
28
var n = - 1 ;
@@ -37,13 +31,15 @@ describe('modifyChildren()', function () {
37
31
38
32
modifyChildren ( function ( child , index , parent ) {
39
33
n ++ ;
40
- equal ( child , values [ n ] ) ;
41
- equal ( index , n ) ;
42
- equal ( parent , context ) ;
34
+ st . strictEqual ( child , values [ n ] ) ;
35
+ st . strictEqual ( index , n ) ;
36
+ st . strictEqual ( parent , context ) ;
43
37
} ) ( context ) ;
38
+
39
+ st . end ( ) ;
44
40
} ) ;
45
41
46
- it ( 'should work when new children are added' , function ( ) {
42
+ t . test ( 'should work when new children are added' , function ( st ) {
47
43
var values = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ] ;
48
44
var n = - 1 ;
49
45
@@ -54,31 +50,35 @@ describe('modifyChildren()', function () {
54
50
parent . children . push ( parent . children . length ) ;
55
51
}
56
52
57
- equal ( child , values [ n ] ) ;
58
- equal ( index , values [ n ] ) ;
53
+ st . strictEqual ( child , values [ n ] ) ;
54
+ st . strictEqual ( index , values [ n ] ) ;
59
55
} ) ( { children : [ 0 , 1 , 2 , 3 ] } ) ;
56
+
57
+ st . end ( ) ;
60
58
} ) ;
61
59
62
- it ( 'should skip forwards' , function ( ) {
60
+ t . test ( 'should skip forwards' , function ( st ) {
63
61
var values = [ 0 , 1 , 2 , 3 ] ;
64
62
var n = - 1 ;
65
63
var context = { } ;
66
64
67
65
context . children = [ 0 , 1 , 3 ] ;
68
66
69
67
modifyChildren ( function ( child , index , parent ) {
70
- equal ( child , values [ ++ n ] ) ;
68
+ st . strictEqual ( child , values [ ++ n ] ) ;
71
69
72
70
if ( child === 1 ) {
73
71
parent . children . splice ( index + 1 , 0 , 2 ) ;
74
72
return index + 1 ;
75
73
}
76
74
} ) ( context ) ;
77
75
78
- deepEqual ( context . children , values ) ;
76
+ st . deepEqual ( context . children , values ) ;
77
+
78
+ st . end ( ) ;
79
79
} ) ;
80
80
81
- it ( 'should skip backwards' , function ( ) {
81
+ t . test ( 'should skip backwards' , function ( st ) {
82
82
var invocations = [ 0 , 1 , - 1 , 0 , 1 , 2 , 3 ] ;
83
83
var n = - 1 ;
84
84
var context = { } ;
@@ -87,7 +87,7 @@ describe('modifyChildren()', function () {
87
87
context . children = [ 0 , 1 , 2 , 3 ] ;
88
88
89
89
modifyChildren ( function ( child , index , parent ) {
90
- equal ( child , invocations [ ++ n ] ) ;
90
+ st . strictEqual ( child , invocations [ ++ n ] ) ;
91
91
92
92
if ( ! inserted && child === 1 ) {
93
93
inserted = true ;
@@ -96,6 +96,10 @@ describe('modifyChildren()', function () {
96
96
}
97
97
} ) ( context ) ;
98
98
99
- deepEqual ( context . children , [ - 1 , 0 , 1 , 2 , 3 ] ) ;
99
+ st . deepEqual ( context . children , [ - 1 , 0 , 1 , 2 , 3 ] ) ;
100
+
101
+ st . end ( ) ;
100
102
} ) ;
103
+
104
+ t . end ( ) ;
101
105
} ) ;
0 commit comments