Skip to content

Commit

Permalink
Merge pull request canjs#961 from bitovi/whitecolor-define-contexts-test
Browse files Browse the repository at this point in the history
Define contexts test
  • Loading branch information
justinbmeyer committed May 4, 2014
2 parents 5d6f8d4 + c128282 commit bb94071
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions map/define/define_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,76 @@ steal("can/map/define", "can/test", function () {

});

test("serialize context", function(){
var context, serializeContext;
var MyMap = can.Map.extend({
define: {
name: {
serialize: function(obj){
context = this;
return obj;
}
}
},
serialize: function(){
serializeContext = this;
can.Map.prototype.serialize.apply(this, arguments);

}
});

var map = new MyMap();
map.serialize();
equal(context, map);
equal(serializeContext, map);
});

test("methods contexts", function(){
var contexts = {};
var MyMap = can.Map.extend({
define: {
name: {
value: 'John Galt',

get: function(obj){
contexts.get = this;
return obj;
},

remove: function(obj){
contexts.remove = this;
return obj;
},

set: function(obj){
contexts.set = this;
return obj;
},

serialize: function(obj){
contexts.serialize = this;
return obj;
},

type: function(val){
contexts.type = this;
return val;
}
}

}
});

var map = new MyMap();
map.serialize();
map.removeAttr('name');

equal(contexts.get, map);
equal(contexts.remove, map);
equal(contexts.set, map);
equal(contexts.serialize, map);
equal(contexts.type, map);
});


});

0 comments on commit bb94071

Please sign in to comment.