diff options
| author | Jeff Cross | 2013-07-24 10:17:24 -0700 | 
|---|---|---|
| committer | Jeff Cross | 2013-08-09 13:14:12 -0700 | 
| commit | 3ee744cc63a24b127d6a5f632934bb6ed2de275a (patch) | |
| tree | d66bab80608d1ef959fd7fd871e9493dad24d928 /test | |
| parent | 94ec84e7b9c89358dc00e4039009af9e287bbd05 (diff) | |
| download | angular.js-3ee744cc63a24b127d6a5f632934bb6ed2de275a.tar.bz2 | |
fix(re-bootstrap): Throw an error when bootstrapping a bootstrapped element.
Nothing would prevent a user from accidentally calling angular.bootstrap on an element that had already been bootstrapped. If this was done, odd behavior could manifest in an application, causing different scopes to update the same DOM, and causing debugger confusion.
This fix adds a check inside of angular.bootstrap to check if the passed-in element already has an injector, and if so, will throw an error.
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 26 | 
1 files changed, 26 insertions, 0 deletions
| diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 56fc985c..f049c2fd 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -656,6 +656,32 @@ describe('angular', function() {          /\[\$injector:modulerr] Failed to instantiate module doesntexist due to:\n.*\[\$injector:nomod] Module 'doesntexist' is not available! You either misspelled the module name or forgot to load it\./        );      }); + + +    it('should complain if an element has already been bootstrapped', function () { +      var element = jqLite('<div>bootstrap me!</div>'); +      angular.bootstrap(element); + +      expect(function () { +        angular.bootstrap(element); +      }).toThrowMatching( +        /\[ng:btstrpd\] App Already Bootstrapped with this Element '<div class="?ng\-scope"?( ng\-[0-9]+="?[0-9]+"?)?>'/i +      ); + +      dealoc(element); +    }); + + +    it('should complain if manually bootstrapping a document whose <html> element has already been bootstrapped', function () { +      angular.bootstrap(document.getElementsByTagName('html')[0]); +      expect(function () { +        angular.bootstrap(document); +      }).toThrowMatching( +        /\[ng:btstrpd\] App Already Bootstrapped with this Element 'document'/i +      ); + +      dealoc(document); +    })    }); | 
