From 589d18c01a7c3e48cfcbb239638f192a863e039b Mon Sep 17 00:00:00 2001 From: Alan Hoffmeister Date: Tue, 30 Apr 2019 16:49:48 -0300 Subject: [PATCH] Implement Element.tagName and Element.ownerDocument --- src/undom.js | 5 ++++- test/undom.js | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/undom.js b/src/undom.js index a11f04b..bd5dde4 100644 --- a/src/undom.js +++ b/src/undom.js @@ -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); } @@ -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) { diff --git a/test/undom.js b/test/undom.js index 3430255..dc7fa34 100644 --- a/test/undom.js +++ b/test/undom.js @@ -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'); @@ -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');