Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/undom.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function createEnvironment() {
this.style = {};
}

get tagName() { return this.nodeName; }
get className() { return this.getAttribute('class'); }
set className(val) { this.setAttribute('class', val); }

Expand Down Expand Up @@ -158,7 +159,9 @@ function createEnvironment() {
}

createElement(type) {
return new Element(null, String(type).toUpperCase());
let element = new Element(null, String(type).toUpperCase());
element.ownerDocument = this;
return element;
}

createElementNS(ns, type) {
Expand Down
11 changes: 11 additions & 0 deletions test/undom.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ describe('undom', () => {
expect(document.createElement('div')).to.be.an.instanceOf(document.Element);
});

it('should generate correct ownerDocument', () => {
expect(document.createElement('div')).to.have.property('ownerDocument', document);
});

it('should generate correct nodeNames', () => {
expect(document.createElement('div')).to.have.property('nodeName', 'DIV');
expect(document.createElement('section')).to.have.property('nodeName', 'SECTION');
Expand All @@ -51,6 +55,13 @@ describe('undom', () => {
describe('Element', () => {
let document = undom();

describe('tagName', () => {
it('should return the correct tagName', () => {
let element = document.createElement('div');
expect(element).to.have.property('tagName', 'DIV');
});
});

describe('#appendChild', () => {
it('should set parentNode', () => {
let child = document.createElement('span');
Expand Down