@@ -2,9 +2,9 @@ import Tree from '../tree';
2
2
import { networkInterfaces } from 'os' ;
3
3
4
4
describe ( 'Tree unit test' , ( ) => {
5
- describe ( 'Constructor' , ( ) => {
6
- const newTree = new Tree ( { } ) ;
5
+ const newTree = new Tree ( { } ) ;
7
6
7
+ describe ( 'Constructor' , ( ) => {
8
8
it ( 'should be able to create a newTree' , ( ) => {
9
9
expect ( newTree . state ) . toEqual ( { } ) ;
10
10
} ) ;
@@ -31,29 +31,35 @@ describe('Tree unit test', () => {
31
31
32
32
/**
33
33
*
34
- * the tree should have initial values of state, name, etc to be default as per newly created tree
34
+ * ^^
35
+ * the tree should have initial values of state,
36
+ * name, etc to be default as per newly created tree
37
+ * update the add child and add sibling tests
35
38
*
39
+ * update the clean tree copy test to make it test for deep equaltiy? (note:
40
+ * this test may always fail if we make it so because there is no way to have deep equalituy
41
+ * with some shit that isn't allowed)
36
42
*/
37
43
38
44
describe ( 'Adding children' , ( ) => {
39
- let newTree = new Tree ( { } ) ;
40
- let returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
41
-
42
- it ( 'should be able to add a child' , ( ) => {
43
- expect ( typeof newTree . children ) . toEqual ( 'object' ) ;
44
- expect ( Array . isArray ( newTree . children ) ) . toBeTruthy ;
45
- } )
45
+ const returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
46
46
47
- it ( `its parent should be newTree` , ( ) => {
47
+ it ( 'should have the child be in the children\'s array property' , ( ) => {
48
+ // check if returnChild is in the children array property of tree that invoked addChild
49
+ expect ( newTree . children ) . toContain ( returnChild ) ;
50
+ } ) ;
51
+
52
+ it ( 'should have the object that invoked it be it\'s parent' , ( ) => {
53
+ // checking parent to be the tree that invoked addChild
48
54
expect ( returnChild . parent ) . toEqual ( newTree ) ;
49
- } )
55
+ } ) ;
50
56
51
57
it ( 'parent now contains an array of children and each children is a valid tree' , ( ) => {
52
58
expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'state' ) ;
53
59
expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'name' ) ;
54
60
expect ( newTree . children [ 0 ] ) . toHaveProperty ( 'componentData' ) ;
55
- } )
56
- } )
61
+ } ) ;
62
+ } ) ;
57
63
58
64
describe ( 'Adding sibling' , ( ) => {
59
65
let newTree = new Tree ( { } ) ;
@@ -75,27 +81,6 @@ describe('Tree unit test', () => {
75
81
} )
76
82
} )
77
83
78
-
79
- describe ( 'Adding sibling' , ( ) => {
80
- let newTree = new Tree ( { } ) ;
81
- let returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
82
- let returnSibling = returnChild . addSibling ( 'stateful' , 'child' , { } , null ) ;
83
- it ( 'the tree now has 2 children' , ( ) => {
84
- expect ( newTree . children . length ) . toBe ( 2 ) ;
85
- } )
86
-
87
- it ( 'both of the children has the parent as this tree' , ( ) => {
88
- expect ( newTree . children [ 0 ] ) . toEqual ( returnChild ) ;
89
- expect ( newTree . children [ 1 ] ) . toEqual ( returnSibling ) ;
90
- } )
91
-
92
- it ( 'both of the children has the parent as this tree' , ( ) => {
93
- expect ( returnChild . parent ) . toEqual ( newTree ) ;
94
- expect ( returnSibling . parent ) . toEqual ( newTree ) ;
95
- } )
96
- } )
97
-
98
-
99
84
describe ( 'Copy & clean tree' , ( ) => {
100
85
let newTree = new Tree ( { } ) ;
101
86
let returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
0 commit comments