@@ -2,6 +2,7 @@ import { MockDocument } from '../document';
22import { MockWindow , cloneWindow } from '../window' ;
33import { MockElement , MockHTMLElement } from '../node' ;
44import { XLINK_NS } from '../../runtime/runtime-constants' ;
5+ import { MockSVGElement } from '../element' ;
56
67
78describe ( 'element' , ( ) => {
@@ -119,6 +120,69 @@ describe('element', () => {
119120 } ) ;
120121 } ) ;
121122
123+ describe ( 'namespaceURI' , ( ) => {
124+ it ( 'HTMLElement namespaceURI is always http://www.w3.org/1999/xhtml' , ( ) => {
125+ const htmlElement = new MockHTMLElement ( doc , 'svg' ) ;
126+ expect ( htmlElement . namespaceURI ) . toEqual ( 'http://www.w3.org/1999/xhtml' ) ;
127+
128+ const createdElement1 = doc . createElement ( 'div' ) ;
129+ expect ( createdElement1 . namespaceURI ) . toEqual ( 'http://www.w3.org/1999/xhtml' ) ;
130+
131+ const createdElement2 = doc . createElement ( 'svg' ) ;
132+ expect ( createdElement2 . namespaceURI ) . toEqual ( 'http://www.w3.org/1999/xhtml' ) ;
133+ expect ( createdElement2 instanceof MockHTMLElement ) . toBe ( true ) ;
134+
135+ const createdElement3 = doc . createElementNS ( 'http://www.w3.org/1999/xhtml' , 'svg' ) ;
136+ expect ( createdElement3 . namespaceURI ) . toEqual ( 'http://www.w3.org/1999/xhtml' ) ;
137+ expect ( createdElement3 instanceof MockHTMLElement ) . toBe ( true ) ;
138+ } ) ;
139+
140+ it ( 'Element namespace is null by defualt' , ( ) => {
141+ const element = new MockElement ( doc , 'svg' ) ;
142+ expect ( element . namespaceURI ) . toEqual ( null ) ;
143+ } ) ;
144+
145+ it ( 'createElementNS sets the namespace' , ( ) => {
146+ const element = doc . createElementNS ( 'random' , 'svg' ) ;
147+ expect ( element . namespaceURI ) . toEqual ( 'random' ) ;
148+ expect ( element instanceof MockSVGElement ) . toBe ( false ) ;
149+
150+ const element1 = doc . createElementNS ( 'http://www.w3.org/2000/svg' , 'svg' ) ;
151+ expect ( element1 . namespaceURI ) . toEqual ( 'http://www.w3.org/2000/svg' ) ;
152+ expect ( element1 instanceof MockSVGElement ) . toBe ( true ) ;
153+ } ) ;
154+ } ) ;
155+
156+ describe ( 'tagName' , ( ) => {
157+ it ( 'Element tagName/nodeName is case sensible' , ( ) => {
158+ const element = new MockElement ( doc , 'myElement' ) ;
159+ expect ( element . tagName ) . toEqual ( 'myElement' ) ;
160+ expect ( element . nodeName ) . toEqual ( 'myElement' ) ;
161+
162+ const foreignObject = document . createElementNS ( 'http://www.w3.org/2000/svg' , 'foreignObject' ) ;
163+ expect ( foreignObject . tagName ) . toEqual ( 'foreignObject' ) ;
164+ expect ( foreignObject . nodeName ) . toEqual ( 'foreignObject' ) ;
165+ } ) ;
166+
167+ it ( 'HTMLElement tagName/nodeName is case insensible' , ( ) => {
168+ const element = new MockHTMLElement ( doc , 'myElement' ) ;
169+ expect ( element . tagName ) . toEqual ( 'MYELEMENT' ) ;
170+ expect ( element . nodeName ) . toEqual ( 'MYELEMENT' ) ;
171+
172+ const foreignObject = document . createElement ( 'foreignObject' ) ;
173+ expect ( foreignObject . tagName ) . toEqual ( 'FOREIGNOBJECT' ) ;
174+ expect ( foreignObject . nodeName ) . toEqual ( 'FOREIGNOBJECT' ) ;
175+
176+ const foreignObject2 = document . createElementNS ( 'http://www.w3.org/1999/xhtml' , 'foreignObject' ) ;
177+ expect ( foreignObject2 . tagName ) . toEqual ( 'FOREIGNOBJECT' ) ;
178+ expect ( foreignObject2 . nodeName ) . toEqual ( 'FOREIGNOBJECT' ) ;
179+
180+ const createdElement = document . createElement ( 'myElement' ) ;
181+ expect ( createdElement . tagName ) . toEqual ( 'MYELEMENT' ) ;
182+ expect ( createdElement . nodeName ) . toEqual ( 'MYELEMENT' ) ;
183+ } ) ;
184+ } ) ;
185+
122186 describe ( 'attributes' , ( ) => {
123187 it ( 'attributes are case sensible in Element' , ( ) => {
124188 const element = new MockElement ( doc , 'div' ) ;
0 commit comments