this._$.detach();
if(existed) {
this.triggerChangeEvent('nodeDetached', {parent: parent});
+ if(!parent) {
+ // This was the root of the document
+ this.document._defineDocumentProperties(null);
+ }
}
return this;
},
_defineDocumentProperties: function($document) {
var doc = this;
Object.defineProperty(doc, 'root', {get: function() {
+ if(!$document) {
+ return null;
+ }
return doc.createDocumentNode($document[0]);
}, configurable: true});
Object.defineProperty(doc, 'dom', {get: function() {
+ if(!$document) {
+ return null;
+ }
return $document[0];
}, configurable: true});
}
describe('Manipulations', function() {
+ describe('detaching nodes', function() {
+ it('can detach document root node', function() {
+ var doc = getDocumentFromXML('<div></div>');
+
+ doc.root.detach();
+ expect(doc.root).to.equal(null);
+ });
+ });
+
describe('replacing node with another one', function() {
it('replaces node with another one', function() {
var doc = getDocumentFromXML('<div><a></a></div>'),