diff options
| author | Misko Hevery | 2010-03-31 17:56:16 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-03-31 18:18:10 -0700 | 
| commit | 11a6431f8926c557f3c58408dacc98466e76cde1 (patch) | |
| tree | ab36304fd373d0947ca36c577e25ca87a1c894af /test/ScopeSpec.js | |
| parent | 35a91085004e31f786df1e0011bc26ed0142ab4d (diff) | |
| download | angular.js-11a6431f8926c557f3c58408dacc98466e76cde1.tar.bz2 | |
started to add services
Diffstat (limited to 'test/ScopeSpec.js')
| -rw-r--r-- | test/ScopeSpec.js | 44 | 
1 files changed, 40 insertions, 4 deletions
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 7e1a899f..8d2a0ed4 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -11,7 +11,8 @@ describe('scope/model', function(){      model.$set('name', 'adam');      expect(model.name).toEqual('adam');      expect(model.$get('name')).toEqual('adam'); -    expect(model.$parent).toEqual(parent); +    expect(model.$parent).toEqual(model); +    expect(model.$root).toEqual(model);    });    //$eval @@ -78,15 +79,50 @@ describe('scope/model', function(){      expect(model.printed).toEqual(true);    }); - -    //$tryEval    it('should report error on element', function(){ - +    var scope = createScope(); +    scope.$tryEval('throw "myerror";', function(error){ +      scope.error = error; +    }); +    expect(scope.error).toEqual('myerror');    });    it('should report error on visible element', function(){ +    var element = jqLite('<div></div>'); +    var scope = createScope(); +    scope.$tryEval('throw "myError"', element); +    expect(element.attr('ng-error')).toEqual('"myError"'); // errors are jsonified +    expect(element.hasClass('ng-exception')).toBeTruthy(); +  }); + +  // $onEval + +  it("should eval using priority", function(){ +    var scope = createScope(); +    scope.log = ""; +    scope.$onEval('log = log + "middle;"'); +    scope.$onEval(-1, 'log = log + "first;"'); +    scope.$onEval(1, 'log = log + "last;"'); +    scope.$eval(); +    expect(scope.log).toEqual('first;middle;last;'); +  }); + +  // Services are initialized +  it("should inject services", function(){ +    var scope = createScope(serviceAdapter({ +      $window: function(){ +      return window; +    } +    })); +    expect(scope.$window).toEqual(window); +  }); +  it("should have $root and $parent", function(){ +    var parent = createScope(); +    var scope = createScope(parent); +    expect(scope.$root).toEqual(parent); +    expect(scope.$parent).toEqual(parent);    });  });  | 
