Changeset 7691

Show
Ignore:
Timestamp:
03/19/07 23:06:32 (22 months ago)
Author:
jburke
Message:

Refs #2500. Tests for dojo.getObject()

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/tests/_base/_loader/bootstrap.js

    r7669 r7691  
    1414                }, 
    1515 
     16                { 
     17                        name: "getObject", 
     18                        setUp: function(){ 
     19                                //Set an object in global scope. 
     20                                dojo.global().globalValue = { 
     21                                        color: "blue", 
     22                                        size: 20 
     23                                }; 
     24                                 
     25                                //Set up an object in a specific scope. 
     26                                this.foo = { 
     27                                        bar: { 
     28                                                color: "red", 
     29                                                size: 100 
     30                                        } 
     31                                }; 
     32                        }, 
     33                        runTest: function(t){ 
     34                                //Test for existing object using global as root path. 
     35                                var globalVar = dojo.getObject("globalValue"); 
     36                                t.assertTrue(typeof(globalVar) == "object"); 
     37                                t.assertEqual("blue", globalVar.color); 
     38                                t.assertEqual(20, globalVar.size); 
     39                                t.assertEqual("blue", dojo.getObject("globalValue.color")); 
     40                                 
     41                                //Test for non-existent object using global as root path. 
     42                                //Then create it. 
     43                                t.assertFalse(dojo.getObject("something.thatisNew")); 
     44                                t.assertTrue(typeof(dojo.getObject("something.thatisNew", true)) == "object"); 
     45                                 
     46                                //Test for existing object using another object as root path. 
     47                                var scopedVar = dojo.getObject("foo.bar", false, this); 
     48                                t.assertTrue(typeof(scopedVar) == "object"); 
     49                                t.assertEqual("red", scopedVar.color); 
     50                                t.assertEqual(100, scopedVar.size); 
     51                                t.assertEqual("red", dojo.getObject("foo.bar.color", true, this)); 
     52                                 
     53                                //Test for existing object using another object as root path. 
     54                                //Then create it. 
     55                                t.assertFalse(dojo.getObject("something.thatisNew", false, this)); 
     56                                t.assertTrue(typeof(dojo.getObject("something.thatisNew", true, this)) == "object"); 
     57                        }, 
     58                        tearDown: function(){ 
     59                                //Clean up global object that should not exist if 
     60                                //the test is re-run. 
     61                                delete dojo.global().something; 
     62                                delete this.something; 
     63                        } 
     64                }, 
     65                 
    1666                { 
    1767                        name: "exists",