Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2687 because Extending Natives makes the document.id/toElement combo stop working. #2688

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Source/Class/Class.js
Expand Up @@ -23,6 +23,7 @@ var Class = this.Class = new Type('Class', function(params){
reset(this);
if (newClass.$prototyping) return this;
this.$caller = null;
this.$family = null;
var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
this.$caller = this.caller = null;
return value;
Expand Down
63 changes: 63 additions & 0 deletions Specs/Class/Class.js
Expand Up @@ -282,4 +282,67 @@ describe('Class toString', function(){

});

describe('Class.toElement', function(){

var MyParentElement = new Class({

initialize: function(element){
this.element = element;
},

toElement: function(){
return this.element;
}

});

var MyChildElement = new Class({

Extends: MyParentElement,

initialize: function(element){
this.parent(element);
}

});

var MyArrayElement = new Class({

Extends: Array,

initialize: function(element){
this.element = element;
},

toElement: function(){
return this.element;
}

});

it('should return an element when a class instance is passed to document.id', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyParentElement(element);

expect(document.id(instance)).toBe(element);
});

it('should call the toElement() method in parent class if none is defined in child', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyChildElement(element);

expect(document.id(instance)).toBe(element);
expect(instance instanceof MyParentElement).toEqual(true);
});

it('should call toElement() when extending natives (String, Array, Object)', function(){
var element = new Element('div', {'class': 'my-element'});
var instance = new MyArrayElement(element);

expect(document.id(instance)).toBe(element);
expect(instance instanceof Array).toEqual(true);
});

});

})();