diff options
| author | Chris Chua | 2013-11-24 14:40:46 -0800 | 
|---|---|---|
| committer | Vojta Jina | 2013-12-16 16:39:13 -0800 | 
| commit | 2f91cfd0d2986899c38641100c1851b2f9d3888a (patch) | |
| tree | 944561843e11e07bfd0d2986c5560539eabde3e0 /test/jqLiteSpec.js | |
| parent | d5c5e2b5848dcb312390549a92c94c76822a5f4f (diff) | |
| download | angular.js-2f91cfd0d2986899c38641100c1851b2f9d3888a.tar.bz2 | |
fix(jqLite): support unbind self within handler
If an event handler unbinds itself, the next event handler on the same
event and element doesn't get executed.
This works fine in jQuery, and since jqLite doesn't support .one, this
might be a common use case.
Diffstat (limited to 'test/jqLiteSpec.js')
| -rw-r--r-- | test/jqLiteSpec.js | 20 | 
1 files changed, 20 insertions, 0 deletions
| diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index c4f47dcd..3a8fd404 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1120,6 +1120,26 @@ describe('jqLite', function() {      }); +    it('should deregister specific listener within the listener and call subsequent listeners', function() { +      var aElem = jqLite(a), +          clickSpy = jasmine.createSpy('click'), +          clickOnceSpy = jasmine.createSpy('clickOnce').andCallFake(function() { +            aElem.off('click', clickOnceSpy); +          }); + +      aElem.on('click', clickOnceSpy); +      aElem.on('click', clickSpy); + +      browserTrigger(a, 'click'); +      expect(clickOnceSpy).toHaveBeenCalledOnce(); +      expect(clickSpy).toHaveBeenCalledOnce(); + +      browserTrigger(a, 'click'); +      expect(clickOnceSpy).toHaveBeenCalledOnce(); +      expect(clickSpy.callCount).toBe(2); +    }); + +      it('should deregister specific listener for multiple types separated by spaces', function() {        var aElem = jqLite(a),            masterSpy = jasmine.createSpy('master'), | 
