mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
|
|
||
|
describe 'Concrete'
|
||
|
describe 'Super'
|
||
|
before
|
||
|
$('body').append('<div id="dom_test"></div>')
|
||
|
end
|
||
|
after
|
||
|
$('#dom_test').remove()
|
||
|
end
|
||
|
|
||
|
before_each
|
||
|
$.concrete.clear_all_rules()
|
||
|
$('#dom_test').html('<div id="a" class="a b c"></div><div id="b" class="c d e"></div>')
|
||
|
end
|
||
|
|
||
|
it 'can call the super function'
|
||
|
var a = 1;
|
||
|
$('#a').concrete({
|
||
|
foo: function(){a *= 2;}
|
||
|
});
|
||
|
$('#a.a').concrete({
|
||
|
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').concrete({
|
||
|
foo: function(){a *= 2; this._super();}
|
||
|
});
|
||
|
$('#a.a').concrete({
|
||
|
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').concrete({
|
||
|
foo: function(){ list.push('foo'); this.bar(); },
|
||
|
bar: function(){ list.push('bar'); }
|
||
|
});
|
||
|
$('#a.a').concrete({
|
||
|
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
|
||
|
end
|
||
|
end
|