/
map_test.js
59 lines (40 loc) · 1020 Bytes
/
map_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
56
57
58
59
(function(undefined) {
module('can/map')
test("Basic Map",4,function(){
var state = new can.Map({
category : 5,
productType : 4
});
var added;
state.bind("change", function(ev, attr, how, val, old){
equal(attr, "category", "correct change name")
equal(how, "set")
equal(val,6, "correct")
equal(old,5, "correct")
});
state.attr("category",6);
state.unbind("change");
});
test("Nested Map", 5, function(){
var me = new can.Map({
name : {first: "Justin", last: "Meyer"}
});
ok(me.attr("name") instanceof can.Map);
me.bind("change", function(ev, attr, how, val, old){
equal(attr, "name.first", "correct change name")
equal(how, "set")
equal(val,"Brian", "correct")
equal(old,"Justin", "correct")
})
me.attr("name.first","Brian");
me.unbind("change")
})
test("remove attr", function(){
var state = new can.Map({
category : 5,
productType : 4
});
state.removeAttr("category");
deepEqual( can.Map.keys(state), ["productType"], "one property" );
})
})();