describe('Entwine', function(){ beforeEach(function(){ $('body').append('
'); }); afterEach(function(){ $('#dom_test').remove(); }); describe('Events', function(){ beforeEach(function(){ $.entwine.synchronous_mode(); $.entwine.clear_all_rules(); $('#dom_test').html(''); }); it('calls onfoo when foo triggered', function(){ var a = 0; $('#a').entwine({ onfoo: function(){a = 1;} }); expect(a).toEqual(0); $('#a').trigger('foo'); expect(a).toEqual(1); }); it('only calls most specific onfoo when foo triggered', function(){ var a = 0, b = 0; $('#a.a').entwine({ onfoo: function(){a = 1;} }); $('#a').entwine({ onfoo: function(){b = 1;} }); expect(a).toEqual(0); expect(b).toEqual(0); $('#a').trigger('foo'); expect(a).toEqual(1); expect(b).toEqual(0); }); it('calls namespaced onfoo when foo triggered', function(){ var a = 0; $('#a').entwine('bar', function($){return{ onfoo: function(){a = 1;} };}); expect(a).toEqual(0); $('#a').trigger('foo'); expect(a).toEqual(1); }); it('calls most specific namespaced onfoo and most specific non-namespaced onfoo when foo triggered', function(){ var a = 0, b = 0, c = 0, d = 0; $('#a.a').entwine({ onfoo: function(){a = 1;} }); $('#a').entwine({ onfoo: function(){b = 1;} }); $('#a.a').entwine('bar', function($){return{ onfoo: function(){c = 1;} };}); $('#a').entwine('bar', function($){return{ onfoo: function(){d = 1;} };}); expect([a, b, c, d]).toEqual([0, 0, 0, 0]); $('#a').trigger('foo'); expect([a, b, c, d]).toEqual([1, 0, 1, 0]); }); it('calls up correctly on _super', function(){ var a = 0, b = 0; $('#a').entwine({ onfoo: function(){a += 1;} }); $('#a.a').entwine({ onfoo: function(){this._super(); b += 1; this._super();} }); expect([a, b]).toEqual([0, 0]); $('#a').trigger('foo') expect([a, b]).toEqual([2, 1]); }); it('passes event object', function(){ var event; $('#a').entwine({ onfoo: function(e){event = e;} }); $('#a').trigger('foo'); expect(event.type).toBeDefined(); expect(event.type).toEqual('foo'); expect(event.target).toHaveAttr('id', 'a'); }); it('delegates submit events to forms', function(){ var a = 0; $('