/public/javascripts/dojo/release/dojo/dojo/tests/_base/_loader/bootstrap.js

http://enginey.googlecode.com/ · JavaScript · 86 lines · 66 code · 10 blank · 10 comment · 4 complexity · 4979990b7e2ea18775322d3d1fd12fe3 MD5 · raw file

  1. if(!dojo._hasResource["tests._base._loader.bootstrap"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2. dojo._hasResource["tests._base._loader.bootstrap"] = true;
  3. dojo.provide("tests._base._loader.bootstrap");
  4. tests.register("tests._base._loader.bootstrap",
  5. [
  6. function hasConsole(t){
  7. t.assertTrue("console" in dojo.global);
  8. t.assertTrue("assert" in console);
  9. t.assertEqual("function", typeof console.assert);
  10. },
  11. {
  12. name: "getObject",
  13. setUp: function(){
  14. //Set an object in global scope.
  15. dojo.global.globalValue = {
  16. color: "blue",
  17. size: 20
  18. };
  19. //Set up an object in a specific scope.
  20. this.foo = {
  21. bar: {
  22. color: "red",
  23. size: 100
  24. }
  25. };
  26. },
  27. runTest: function(t){
  28. //Test for existing object using global as root path.
  29. var globalVar = dojo.getObject("globalValue");
  30. t.is("object", (typeof globalVar));
  31. t.assertEqual("blue", globalVar.color);
  32. t.assertEqual(20, globalVar.size);
  33. t.assertEqual("blue", dojo.getObject("globalValue.color"));
  34. //Test for non-existent object using global as root path.
  35. //Then create it.
  36. t.assertFalse(dojo.getObject("something.thatisNew"));
  37. t.assertTrue(typeof(dojo.getObject("something.thatisNew", true)) == "object");
  38. //Test for existing object using another object as root path.
  39. var scopedVar = dojo.getObject("foo.bar", false, this);
  40. t.assertTrue(typeof(scopedVar) == "object");
  41. t.assertEqual("red", scopedVar.color);
  42. t.assertEqual(100, scopedVar.size);
  43. t.assertEqual("red", dojo.getObject("foo.bar.color", true, this));
  44. //Test for existing object using another object as root path.
  45. //Then create it.
  46. t.assertFalse(dojo.getObject("something.thatisNew", false, this));
  47. t.assertTrue(typeof(dojo.getObject("something.thatisNew", true, this)) == "object");
  48. },
  49. tearDown: function(){
  50. //Clean up global object that should not exist if
  51. //the test is re-run.
  52. try{
  53. delete dojo.global.something;
  54. delete this.something;
  55. }catch(e){}
  56. }
  57. },
  58. {
  59. name: "exists",
  60. setUp: function(){
  61. this.foo = {
  62. bar: {}
  63. };
  64. },
  65. runTest: function(t){
  66. t.assertTrue(dojo.exists("foo.bar", this));
  67. t.assertFalse(dojo.exists("foo.bar"));
  68. }
  69. },
  70. function evalWorks(t){
  71. t.assertTrue(dojo.eval("(true)"));
  72. t.assertFalse(dojo.eval("(false)"));
  73. }
  74. ]
  75. );
  76. }