+
+ it('keeps contents', function() {
+ var node = elementNodeFromXML('<div><div></div></div>');
+ node.setTag('header');
+ expect(node.contents()).to.have.length(1);
+ });
+ });
+
+ describe('Setting node attributes', function() {
+ it('can set node attribute', function() {
+ var node = elementNodeFromXML('<div></div>');
+
+ node.setAttr('key', 'value');
+ expect(node.getAttr('key')).to.equal('value');
+ });
+ it('emits nodeAttrChange event', function() {
+ var node = elementNodeFromXML('<div key="value1"></div>'),
+ spy = sinon.spy();
+
+ node.document.on('change', spy);
+ node.setAttr('key', 'value2');
+ var event = spy.args[0][0];
+
+ expect(event.type).to.equal('nodeAttrChange');
+ expect(event.meta.node.sameNode(node)).to.be.true;
+ expect(event.meta.attr).to.equal('key');
+ expect(event.meta.oldVal).to.equal('value1');
+ });
+ });
+
+ });
+ });
+
+ describe('Basic TextNode properties', function() {
+ it('can have its text set', function() {
+ var node = elementNodeFromXML('<div>Alice</div>'),
+ textNode = node.contents()[0];
+
+ textNode.setText('Cat');
+ expect(textNode.getText()).to.equal('Cat');
+ });
+
+ it('emits nodeTextChange', function() {
+ var node = elementNodeFromXML('<div>Alice</div>'),
+ textNode = node.contents()[0],
+ spy = sinon.spy();
+
+ textNode.document.on('change', spy);
+ textNode.setText('Cat');
+
+ var event = spy.args[0][0];
+ expect(event.type).to.equal('nodeTextChange');
+ });
+
+ it('puts NodeElement after itself', function() {
+ var node = elementNodeFromXML('<div>Alice</div>'),
+ textNode = node.contents()[0],
+ returned = textNode.after({tagName:'div'});
+ expect(returned.sameNode(node.contents()[1])).to.be.true;
+ });
+
+ it('puts NodeElement before itself', function() {
+ var node = elementNodeFromXML('<div>Alice</div>'),
+ textNode = node.contents()[0],
+ returned = textNode.before({tagName:'div'});
+ expect(returned.sameNode(node.contents()[0])).to.be.true;
+ });
+
+ describe('Wrapping TextNode contents', function() {
+
+ it('wraps DocumentTextElement', function() {
+ var node = elementNodeFromXML('<section>Alice</section>'),
+ textNode = node.contents()[0];
+
+ var returned = textNode.wrapWith({tagName: 'header'}),
+ parent = textNode.parent(),
+ parent2 = node.contents()[0];
+
+ expect(returned.sameNode(parent)).to.be.equal(true, 'wrapper is a parent');
+ expect(returned.sameNode(parent2)).to.be.equal(true, 'wrapper has a correct parent');
+ expect(returned.getTagName()).to.equal('header');