-
Notifications
You must be signed in to change notification settings - Fork 1
/
bubble_test.js
55 lines (44 loc) · 1.56 KB
/
bubble_test.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
var QUnit = require("steal-qunit");
var CanMap = require("./can-map");
var bubble = require("./bubble");
QUnit.test(".childrenOf should not bubble functions", function(assert){
var map = new CanMap({
fn: function() {}
});
bubble.childrenOf(map, "change");
assert.equal(bubble.events(map.fn, "change"), undefined, "Functions are not bubbled");
});
QUnit.test(".childrenOf should not bubble functions in nested maps", function(assert){
var map = new CanMap({
obj: {
fooFn: function() {},
foo: { bar: "baz" }
}
});
bubble.childrenOf(map, "change");
assert.equal(bubble.events(map.attr("obj").fooFn, "change"), undefined, "Nested maps functions are not bubbled");
assert.equal(bubble.events(map.attr("obj.foo"), "change").length, 1, "Still bubbles nested maps");
});
QUnit.test(".childrenOf should not bubble array", function(assert){
var map = new CanMap({
foo: ['item'],
bar: {
baz: ['anotherItem']
}
});
bubble.childrenOf(map, "change");
assert.equal(bubble.events(map.attr("foo"), "change"), undefined);
assert.equal(bubble.events(map.attr("bar.baz"), "change"), undefined);
assert.ok(true);
});
QUnit.test(".childrenOf should not bind nested non-Observables", function(assert){
var map = new CanMap({
type: Object.create({
label: "hello",
})
});
bubble.childrenOf(map, "change");
assert.equal(bubble.events(map.attr("type"), "change"), undefined, "non-Observable child does not bubble");
map.attr("type", new CanMap({}));
assert.equal(bubble.events(map.attr("type"), "change").length, 1, "replacing with Observable child bubbles");
});