silverstripe-framework/thirdparty/jquery-entwine/spec/spec.entwine.super.js
Ingo Schommer 8256228e69 MINOR Upgraded jQuery.entwine (formerly known as jQuery.concrete) to the latest trunk
MINOR Updated jQuery.concrete references to point to the new "entwine" name

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102695 467b73ca-7a2a-4603-9d3b-597d59a354a9
2010-04-13 05:45:29 +00:00

67 lines
1.7 KiB
JavaScript

describe 'Entwine'
describe 'Super'
before
$('body').append('<div id="dom_test"></div>')
end
after
$('#dom_test').remove()
end
before_each
$.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>')
end
it 'can call the super function'
var a = 1;
$('#a').entwine({
foo: function(){a *= 2;}
});
$('#a.a').entwine({
foo: function(){a += 2; this._super();}
});
$('#a').foo();
a.should.equal 6
end
it 'super to a non-existant class should be ignored'
var a = 1;
$('#a').entwine({
foo: function(){a *= 2; this._super();}
});
$('#a.a').entwine({
foo: function(){a += 2; this._super();}
});
$('#a').foo();
a.should.equal 6
end
it 'can call super from two different functions without screwing up what super points to'
var list = [];
$('#a').entwine({
foo: function(){ list.push('foo'); this.bar(); },
bar: function(){ list.push('bar'); }
});
$('#a.a').entwine({
foo: function(){ list.push('foo2'); this._super(); list.push('foo2'); this._super(); },
bar: function(){ list.push('bar2'); this._super(); }
});
$('#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'
end
end
end