diff options
| author | Igor Minar | 2011-10-26 12:15:07 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-10-26 12:15:07 -0700 | 
| commit | d5ccabce600efb10092fdf0ae033c009026bf4cb (patch) | |
| tree | 3debd4dfe43213252b685ec7fa76459c5337bc9b /test | |
| parent | bb948176aaf6748c0d27772797b4c1490612b917 (diff) | |
| download | angular.js-d5ccabce600efb10092fdf0ae033c009026bf4cb.tar.bz2 | |
fix(ng:view): ignore stale xhr callbacks
A lot of badness happens when we don't ignore stale xhrs. These
raceconditions are only apparent when user clicks through the app very
quckly without waiting for routes to fully load.
Closes #619
Diffstat (limited to 'test')
| -rw-r--r-- | test/widgetsSpec.js | 20 | 
1 files changed, 20 insertions, 0 deletions
diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index adbdf94e..4aa36428 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -539,6 +539,26 @@ describe("widget", function() {        expect(rootScope.log).toEqual(['parent', 'init', 'child']);      }); + +    it('should discard pending xhr callbacks if a new route is requested before the current ' + +        'finished loading', function() { +      // this is a test for a bad race condition that affected feedback + +      $route.when('/foo', {template: 'myUrl1'}); +      $route.when('/bar', {template: 'myUrl2'}); + +      expect(rootScope.$element.text()).toEqual(''); + +      $location.path('/foo'); +      $browser.xhr.expectGET('myUrl1').respond('<div>{{1+3}}</div>'); +      rootScope.$digest(); +      $location.path('/bar'); +      $browser.xhr.expectGET('myUrl2').respond('<div>{{1+1}}</div>'); +      rootScope.$digest(); +      $browser.xhr.flush(); // no that we have to requests pending, flush! + +      expect(rootScope.$element.text()).toEqual('2'); +    });    });  | 
