/
spec.concrete.ctors.js
68 lines (58 loc) · 2.13 KB
/
spec.concrete.ctors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
describe 'Concrete'
describe 'Ctors'
before
$('body').append('<div id="dom_test"></div>')
end
after
$('#dom_test').remove()
end
before_each
$.concrete.synchronous_mode();
$.concrete.clear_all_rules()
$('#dom_test').html('<div id="a" class="a b c"></div>')
end
it 'calls onmatch when new element created'
var a = false;
$('#b').concrete({onmatch: function(){a = true;} });
a.should.be_false
$('#a').after('<div id="b"></div>');
a.should.be_true
end
it 'calls onunmatch when new element deleted'
var a = 0;
$('#b').concrete({onmatch: function(){a = 1;}, onunmatch: function(){a = 2;} });
a.should.equal 0
$('#a').after('<div id="b"></div>');
a.should.equal 1
$('#b').remove();
a.should.equal 2
end
it 'calls onmatch when ruleset matches after class added'
var a = 0;
$('#a.foo').concrete({onmatch: function(){a = 1;} });
a.should.equal 0
$('#a').addClass('foo');
a.should.equal 1
end
it 'calls onmatch in both direct and namespaced onmatch, does not call less specific onmatch'
var a = 0, b=0, c=0, d=0;
$('.foo').concrete({onmatch: function(){a = 1;}})
$('.foo').concrete('bar', function($){return{onmatch: function(){b = 1;}}})
$('#a.foo').concrete({onmatch: function(){c = 1;}})
$('#a.foo').concrete('bar', function($){return{onmatch: function(){d = 1}}})
[a, b, c, d].should.eql [0, 0, 0, 0]
$('#a').addClass('foo');
[a, b, c, d].should.eql [0, 0, 1, 1]
end
it 'calls onmatch in both direct and namespaced onmatch, super works as expected'
var a = 0, b=0, c=0, d=0;
$('.foo').concrete({onmatch: function(){a += 1;}})
$('.foo').concrete('bar', function($){return{onmatch: function(){b += 1;}}})
$('#a.foo').concrete({onmatch: function(){this._super(); c = 1; this._super();}})
$('#a.foo').concrete('bar', function($){return{onmatch: function(){this._super(); d = 1; this._super();}}})
[a, b, c, d].should.eql [0, 0, 0, 0]
$('#a').addClass('foo');
[a, b, c, d].should.eql [2, 2, 1, 1]
end
end
end