diff options
| author | Michał Gołębiowski | 2013-10-16 15:15:21 +0200 | 
|---|---|---|
| committer | Igor Minar | 2013-12-13 02:07:11 -0800 | 
| commit | 3410f65e790a81d457b4f4601a1e760a6f8ede5e (patch) | |
| tree | 2f37146f1399d23ea02de44e8209879eda949e1f /test/jqLiteSpec.js | |
| parent | f3de5b6eac90baf649506072162f36dbc6d2f028 (diff) | |
| download | angular.js-3410f65e790a81d457b4f4601a1e760a6f8ede5e.tar.bz2 | |
perf(jqLite): implement and use the `empty` method in place of `html(‘’)`
jQuery's elem.html('') is way slower than elem.empty(). As clearing
element contents happens quite often in certain scenarios, switching
to using .empty() provides a significant performance boost when using
Angular with jQuery.
Closes #4457
Diffstat (limited to 'test/jqLiteSpec.js')
| -rw-r--r-- | test/jqLiteSpec.js | 25 | 
1 files changed, 23 insertions, 2 deletions
| diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 09be1c1c..c4f47dcd 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -322,7 +322,7 @@ describe('jqLite', function() {      }); -    it('should emit $destroy event if an element is removed via html()', inject(function(log) { +    it('should emit $destroy event if an element is removed via html(\'\')', inject(function(log) {        var element = jqLite('<div><span>x</span></div>');        element.find('span').on('$destroy', log.fn('destroyed')); @@ -333,6 +333,17 @@ describe('jqLite', function() {      })); +    it('should emit $destroy event if an element is removed via empty()', inject(function(log) { +      var element = jqLite('<div><span>x</span></div>'); +      element.find('span').on('$destroy', log.fn('destroyed')); + +      element.empty(); + +      expect(element.html()).toBe(''); +      expect(log).toEqual('destroyed'); +    })); + +      it('should retrieve all data if called without params', function() {        var element = jqLite(a);        expect(element.data()).toEqual({}); @@ -786,7 +797,7 @@ describe('jqLite', function() {      }); -    it('should read/write value', function() { +    it('should read/write a value', function() {        var element = jqLite('<div>abc</div>');        expect(element.length).toEqual(1);        expect(element[0].innerHTML).toEqual('abc'); @@ -797,6 +808,16 @@ describe('jqLite', function() {    }); +  describe('empty', function() { +    it('should write a value', function() { +      var element = jqLite('<div>abc</div>'); +      expect(element.length).toEqual(1); +      expect(element.empty() == element).toBeTruthy(); +      expect(element.html()).toEqual(''); +    }); +  }); + +    describe('on', function() {      it('should bind to window on hashchange', function() {        if (jqLite.fn) return; // don't run in jQuery | 
