11import Tree from '../tree' ;
22import { serializeState , scrubUnserializableMembers } from '../tree' ;
33
4- /**
5- * Created new tree under sibling and copy and clean tree describe block --
6- * Reason is because other tests are adding properties to tree and affecting the child block,
7- * so this was a quick way to test the trees getting reset to initial state
8- *
9- * Possible fix if more time allowed: Making use of beforeEach or afterEach --
10- */
11-
124describe ( 'Serialize state unit test' , ( ) => {
13- const dummyState = { counter : 1 , playerOne : 'X' } ;
5+ const dummyState = {
6+ counter : 1 ,
7+ playerOne : 'X' ,
8+ board : [
9+ [ '' , 'O' , 'X' ] ,
10+ [ '' , 'O' , 'X' ] ,
11+ [ 'O' , 'X' , '' ] ,
12+ ] ,
13+ } ;
14+
15+ const circularState : { [ key : string ] : any } = { } ;
16+ circularState . circ = circularState ;
17+
18+ const serializedState = serializeState ( dummyState ) ;
19+ const serializedCircularState = serializeState ( circularState ) ;
20+
21+ it ( 'should create a deep copy of state' , ( ) => {
22+ expect ( dummyState ) . toEqual ( serializedState ) ;
23+ expect ( dummyState ) . not . toBe ( serializedState ) ;
24+ } ) ;
25+
26+ it ( 'should detect circular state' , ( ) => {
27+ expect ( serializedCircularState ) . toEqual ( 'circularState' ) ;
28+ } ) ;
1429} ) ;
1530
16- describe ( 'Tree unit test' , ( ) => {
31+ describe ( 'Scrub unserialized members unit test' , ( ) => {
32+ const dummyState = {
33+ counter : 1 ,
34+ playerOne : 'X' ,
35+ board : [
36+ [ '' , 'O' , 'X' ] ,
37+ [ '' , 'O' , 'X' ] ,
38+ [ 'O' , 'X' , '' ] ,
39+ ] ,
40+ increment : function ( ) {
41+ this . counter ++ ;
42+ } ,
43+ } ;
44+ const newTree = new Tree ( dummyState ) ;
45+ const scrubbedTree = scrubUnserializableMembers ( newTree ) ;
46+ // make sure return type is tree
47+ it ( 'should be instance of tree' , ( ) => {
48+ expect ( newTree ) . toBeInstanceOf ( Tree ) ;
49+ } ) ;
50+ // make sure function is scrubbed
51+ } ) ;
52+
53+ xdescribe ( 'Tree unit test' , ( ) => {
1754 const newTree = new Tree ( { } ) ;
1855 describe ( 'Constructor' , ( ) => {
1956 it ( 'should be able to create a newTree' , ( ) => {
@@ -35,20 +72,6 @@ describe('Tree unit test', () => {
3572 } ) ;
3673 } ) ;
3774
38- /**
39- *
40- * making sure to adhere to ts practices when goign through tests
41- *
42- * ^^
43- * the tree should have initial values of state,
44- * name, etc to be default as per newly created tree
45- * update the add child and add sibling tests
46- *
47- * update the clean tree copy test to make it test for deep equaltiy? (note:
48- * this test may always fail if we make it so because there is no way to have deep equalituy
49- * with some shit that isn't allowed)
50- */
51-
5275 describe ( 'Adding children' , ( ) => {
5376 const returnChild = newTree . addChild ( 'stateful' , 'child' , { } , null ) ;
5477
0 commit comments