2009-11-21 03:33:06 +01:00
|
|
|
|
2010-04-13 07:45:29 +02:00
|
|
|
describe 'Entwine'
|
2009-11-21 03:33:06 +01:00
|
|
|
describe 'Super'
|
|
|
|
before
|
|
|
|
$('body').append('<div id="dom_test"></div>')
|
|
|
|
end
|
|
|
|
after
|
|
|
|
$('#dom_test').remove()
|
|
|
|
end
|
|
|
|
|
|
|
|
before_each
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine.clear_all_rules()
|
|
|
|
$('#dom_test').html('<div id="a" class="a b c">Foo</div><div id="b" class="c d e">Bar</div>')
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'can call the super function'
|
2010-04-13 07:45:29 +02:00
|
|
|
var a = 1;
|
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
foo: function(){a *= 2;}
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a.a').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
foo: function(){a += 2; this._super();}
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a').foo();
|
|
|
|
a.should.equal 6
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
2010-04-13 07:45:29 +02:00
|
|
|
|
2009-11-21 03:33:06 +01:00
|
|
|
it 'super to a non-existant class should be ignored'
|
2010-04-13 07:45:29 +02:00
|
|
|
var a = 1;
|
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
foo: function(){a *= 2; this._super();}
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a.a').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
foo: function(){a += 2; this._super();}
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a').foo();
|
|
|
|
a.should.equal 6
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
2010-04-13 07:45:29 +02:00
|
|
|
|
2009-11-21 03:33:06 +01:00
|
|
|
it 'can call super from two different functions without screwing up what super points to'
|
2010-04-13 07:45:29 +02:00
|
|
|
var list = [];
|
|
|
|
$('#a').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
foo: function(){ list.push('foo'); this.bar(); },
|
|
|
|
bar: function(){ list.push('bar'); }
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a.a').entwine({
|
2009-11-21 03:33:06 +01:00
|
|
|
foo: function(){ list.push('foo2'); this._super(); list.push('foo2'); this._super(); },
|
|
|
|
bar: function(){ list.push('bar2'); this._super(); }
|
|
|
|
});
|
2010-04-13 07:45:29 +02:00
|
|
|
$('#a').foo();
|
|
|
|
list.should.eql [ 'foo2', 'foo', 'bar2', 'bar', 'foo2', 'foo', 'bar2', 'bar' ]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can override (and call via super) a non-entwine jquery function'
|
|
|
|
var a = 1
|
|
|
|
$('#a').entwine({
|
|
|
|
text: function(){ a = this._super(); }
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#a').text();
|
|
|
|
a.should.equal 'Foo'
|
|
|
|
|
|
|
|
$('#b').text().should.equal 'Bar'
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|