UNPKG

1.81 kBJavaScriptView Raw
1var helpers = require("../../lib/helpers.js");
2var assert = require("assert");
3
4var currentFileMark = ["\t\t\t", "[", __filename, "]", "\n"].join("");
5describe("helpers -> resolve" + currentFileMark, function(){
6
7 it("Simple resolve", function(next){
8 var target = {child: 5};
9 var result = helpers.resolve(target, "child")
10 assert.equal(result, 5);
11 next();
12 });
13
14 it("Deep resolve", function(next){
15 var target = {child: {sub_child: 6}};
16 var result = helpers.resolve(target, "child.sub_child");
17 assert.equal(result, 6);
18 next();
19 });
20
21 it("Resolve nonexisting path evaluates to undefined", function(next){
22 var target = {child: {sub_child: 6}};
23 var result = helpers.resolve(target, "child.sub_child.sub_sub_child_prop");
24 assert.equal(result, undefined);
25 next();
26 });
27
28 it("Resolve simple prototype property", function(next){
29 var Target = function(){};
30 Target.prototype.child = 7;
31 var target = new Target();
32 var result = helpers.resolve(target, "child");
33 assert.equal(result, 7);
34 next();
35 });
36
37 it("Resolve deep prototype property", function(next){
38 var Target = function(){};
39 Target.prototype.child = {aa: 55};
40 var target = new Target();
41 var result = helpers.resolve(target, "child.aa");
42 assert.equal(result, 55);
43 next();
44 });
45
46 it("Resolve deeply nested instances", function(next){
47 var SubChild = function(value){ this.value = value; };
48 var Child = function(){};
49 Child.prototype.sub_child = new SubChild(77);
50 var Target = function(){};
51 Target.prototype.child = new Child();
52 var target = new Target();
53 var result = helpers.resolve(target, "child.sub_child.value");
54 assert.equal(result, 77);
55 next();
56 });
57
58});