How do I compare the tree structure inside an object task with the obj_after tree, without having to actually compare individual nodes in the tree. (one is an instance of a class i.e. with instance methods and the other has no functions just data).
Please read below to understand my exact problem (not so clear from the above).
I am writing a script that builds a GUI based on a js object tree. I am using coffeescript for this.
I would like to create a class that takes a json, and build the tree.
window.GuiTree = class GuiTree
constructor:(json_GUI_tree)->
But the problem I am having is in testing this. I would like to add methods to this class like 'add_node'. That adds a new node to the GuiTree.
So I try this in Jasmine.
obj_before =
1:
type:"text"
name:"task"
label:"Task"
2:
type:"subsection"
sections:
3:
4:
type:"text"
name:"subtask"
label:"Subtask"
obj_after =
1:
type:"text"
name:"task"
label:"Task"
2:
type:"subsection"
sections:
3:
4:
type:"text"
name:"subtask"
label:"Subtask"
5:
type:"text"
name:"subtask"
label:"Subtask"
Where I have added the task 5 to the Gui tree
And I would like to test it like this
task = new GuiTree(obj_before)
expect(task.add(3, node_5)).givesNewTree(obj_after)
The matcher 'givesNewTree' is a custom matcher.
The problem is here !! how do I compare the tree structure inside the object task with the obj_after tree, without having to actually compare individual nodes in the tree. (one is )
To me it looks like lots of error prone code to write to compare the trees. So I may need to write tests to test. Is there a smarter way.