diff options
| author | Igor Minar | 2011-01-19 14:50:29 -0800 | 
|---|---|---|
| committer | Misko Hevery | 2011-01-19 15:53:59 -0800 | 
| commit | 10646c9f6f62dd5130606d07ffe69770b3973f47 (patch) | |
| tree | b91761a062a18aaa386bc854f917c2834b4fd953 /test/widgetsSpec.js | |
| parent | 964e39455526358c5e4bfc94c9d6595687a95865 (diff) | |
| download | angular.js-10646c9f6f62dd5130606d07ffe69770b3973f47.tar.bz2 | |
add ng:view widget
Diffstat (limited to 'test/widgetsSpec.js')
| -rw-r--r-- | test/widgetsSpec.js | 59 | 
1 files changed, 59 insertions, 0 deletions
| diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 48b9f8a1..27c5cb82 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -785,5 +785,64 @@ describe("widget", function(){        expect(element.text()).toEqual('');      });    }); + + +  describe('ng:view', function() { +    var rootScope, partialScope, $route, $location, $browser; + +    beforeEach(function() { +      rootScope = angular.scope(); +      partialScope = angular.compile('<ng:view></ng:view>', rootScope); +      partialScope.$init(); +      $route = rootScope.$service('$route'); +      $location = rootScope.$service('$location'); +      $browser = rootScope.$service('$browser'); +    }); + +    afterEach(function() { +      dealoc(partialScope); +    }); + + +    it('should do nothing when not routes are defined', function() { +      $location.updateHash('/unknown'); +      rootScope.$eval(); +      expect(partialScope.$element.text()).toEqual(''); +    }); + + +    it('should load content via xhr when route changes', function() { +      $route.when('/foo', {controller: angular.noop, template: 'myUrl1'}); +      $route.when('/bar', {controller: angular.noop, template: 'myUrl2'}); + +      expect(partialScope.$element.text()).toEqual(''); + +      $location.updateHash('/foo'); +      $browser.xhr.expectGET('myUrl1').respond('<div>{{1+3}}</div>'); +      rootScope.$eval(); +      $browser.xhr.flush(); +      expect(partialScope.$element.text()).toEqual('4'); + +      $location.updateHash('/bar'); +      $browser.xhr.expectGET('myUrl2').respond('angular is da best'); +      rootScope.$eval(); +      $browser.xhr.flush(); +      expect(partialScope.$element.text()).toEqual('angular is da best'); +    }); + +    it('should remove all content when location changes to an unknown route', function() { +      $route.when('/foo', {controller: angular.noop, template: 'myUrl1'}); + +      $location.updateHash('/foo'); +      $browser.xhr.expectGET('myUrl1').respond('<div>{{1+3}}</div>'); +      rootScope.$eval(); +      $browser.xhr.flush(); +      expect(partialScope.$element.text()).toEqual('4'); + +      $location.updateHash('/unknown'); +      rootScope.$eval(); +      expect(partialScope.$element.text()).toEqual(''); +    }); +  });  }); | 
