diff options
| author | Misko Hevery | 2010-04-29 10:55:22 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-04-29 10:55:22 -0700 | 
| commit | 913729ee0120cc72e13b18d826c6da0fe2b98bf7 (patch) | |
| tree | 678be5150690cec530058a3f8e399f4a30e632e1 /test/servicesSpec.js | |
| parent | fce48eb60a47be87a3d95e0750e54c19c2a346d0 (diff) | |
| download | angular.js-913729ee0120cc72e13b18d826c6da0fe2b98bf7.tar.bz2 | |
fix isssue where the jasmine currentSpec does not get updated and hence everything runs as last spec context.
Diffstat (limited to 'test/servicesSpec.js')
| -rw-r--r-- | test/servicesSpec.js | 136 | 
1 files changed, 72 insertions, 64 deletions
diff --git a/test/servicesSpec.js b/test/servicesSpec.js index f917f968..a7391f34 100644 --- a/test/servicesSpec.js +++ b/test/servicesSpec.js @@ -1,10 +1,17 @@ -describe("services", function(){ +describe("service", function(){    var scope;    beforeEach(function(){      scope = createScope(null, angularService, {});    }); +  afterEach(function(){ +    if (scope && scope.$element) +      scope.$element.remove(); +  }); + + +    it("should inject $window", function(){      expect(scope.$window).toEqual(window);    }); @@ -82,75 +89,76 @@ describe("services", function(){      });    }); -}); -describe("service $invalidWidgets", function(){ -  var scope; -  beforeEach(function(){ -    scope = null; -  }); -  afterEach(function(){ -    if (scope && scope.$element) +  describe("$invalidWidgets", function(){ +    it("should count number of invalid widgets", function(){ +      var scope = compile('<input name="price" ng-required ng-validate="number"></input>').$init(); +      expect(scope.$invalidWidgets.length).toEqual(1); +      scope.price = 123; +      scope.$eval(); +      expect(scope.$invalidWidgets.length).toEqual(0);        scope.$element.remove(); +      scope.price = 'abc'; +      scope.$eval(); +      expect(scope.$invalidWidgets.length).toEqual(1); + +      jqLite(document.body).append(scope.$element); +      scope.$invalidWidgets.clearOrphans(); +      expect(scope.$invalidWidgets.length).toEqual(1); + +      jqLite(document.body).html(''); +      scope.$invalidWidgets.clearOrphans(); +      expect(scope.$invalidWidgets.length).toEqual(0); +    });    }); -  it("should count number of invalid widgets", function(){ -    var scope = compile('<input name="price" ng-required ng-validate="number"></input>').$init(); -    expect(scope.$invalidWidgets.length).toEqual(1); -    scope.price = 123; -    scope.$eval(); -    expect(scope.$invalidWidgets.length).toEqual(0); -    scope.$element.remove(); -    scope.price = 'abc'; -    scope.$eval(); -    expect(scope.$invalidWidgets.length).toEqual(1); - -    jqLite(document.body).append(scope.$element); -    scope.$invalidWidgets.clearOrphans(); -    expect(scope.$invalidWidgets.length).toEqual(1); - -    jqLite(document.body).html(''); -    scope.$invalidWidgets.clearOrphans(); -    expect(scope.$invalidWidgets.length).toEqual(0); + +  describe("$route", function(){ +    it('should route and fire change event', function(){ +      var log = ''; +      function BookChapter() { +        this.log = '<init>'; +      } +      BookChapter.prototype.init = function(){ +        log += 'init();'; +      }; +      var scope = compile('<div></div>').$init(); +      scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); +      scope.$route.when('/Blank'); +      scope.$route.onChange(function(){ +        log += 'onChange();'; +      }); +      scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); +      scope.$eval(); +      expect(log).toEqual('onChange();init();'); +      expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); +      expect(scope.$route.current.scope.log).toEqual('<init>'); +      var lastId = scope.$route.current.scope.$id; + +      log = ''; +      scope.$location.parse('http://server#/Blank?ignore'); +      scope.$eval(); +      expect(log).toEqual('onChange();'); +      expect(scope.$route.current.params).toEqual({ignore:true}); +      expect(scope.$route.current.scope.$id).not.toEqual(lastId); + +      log = ''; +      scope.$location.parse('http://server#/NONE'); +      scope.$eval(); +      expect(log).toEqual('onChange();'); +      expect(scope.$route.current).toEqual(null); + +      scope.$route.when('/NONE', {template:'instant update'}); +      expect(scope.$route.current.template).toEqual('instant update'); +    });    }); -}); -describe("service $route", function(){ -  it('should route and fire change event', function(){ -    var log = ''; -    function BookChapter() { -      this.log = '<init>'; -    } -    BookChapter.prototype.init = function(){ -      log += 'init();'; -    }; -    var scope = compile('<div></div>').$init(); -    scope.$route.when('/Book/:book/Chapter/:chapter', {controller: BookChapter, template:'Chapter.html'}); -    scope.$route.when('/Blank'); -    scope.$route.onChange(function(){ -      log += 'onChange();'; +  describe('$resource', function(){ +    it('should publish to root scope', function(){ +      expect(scope.$resource).toBeTruthy();      }); -    scope.$location.parse('http://server#/Book/Moby/Chapter/Intro?p=123'); -    scope.$eval(); -    expect(log).toEqual('onChange();init();'); -    expect(scope.$route.current.params).toEqual({book:'Moby', chapter:'Intro', p:'123'}); -    expect(scope.$route.current.scope.log).toEqual('<init>'); -    var lastId = scope.$route.current.scope.$id; - -    log = ''; -    scope.$location.parse('http://server#/Blank?ignore'); -    scope.$eval(); -    expect(log).toEqual('onChange();'); -    expect(scope.$route.current.params).toEqual({ignore:true}); -    expect(scope.$route.current.scope.$id).not.toEqual(lastId); - -    log = ''; -    scope.$location.parse('http://server#/NONE'); -    scope.$eval(); -    expect(log).toEqual('onChange();'); -    expect(scope.$route.current).toEqual(null); - -    scope.$route.when('/NONE', {template:'instant update'}); -    expect(scope.$route.current.template).toEqual('instant update');    }); +  }); + +  | 
