Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localName and prefix are not set correctly and consistently #124

Closed
rubys opened this issue Jan 14, 2011 · 4 comments
Closed

localName and prefix are not set correctly and consistently #124

rubys opened this issue Jan 14, 2011 · 4 comments

Comments

@rubys
Copy link
Contributor

rubys commented Jan 14, 2011

In the following, child1 localName is not set, and child2 prefix is wrong:

var html5  = require('html5'),
    jsdom  = require('jsdom'),
    window = jsdom.jsdom().createWindow(null, null, {parser: html5});

var document = window.document;

var child1 = document.createElement('foo');
console.log('createElement:');
console.log('  name:         ' + child1.name);
console.log('  prefix:       ' + child1.prefix);
console.log('  localName:    ' + child1.localName);
console.log('  namespaceURI: ' + child1.namespaceURI);

// note the value of prefix
var child2 = document.createElementNS('http://example.com', 'foo');
console.log('\ncreateElementNS (no prefix):');
console.log('  name:         ' + child2.name);
console.log('  prefix:       ' + child2.prefix);
console.log('  localName:    ' + child2.localName);
console.log('  namespaceURI: ' + child2.namespaceURI);

var child3 = document.createElementNS('http://example.com', 'foo:bar');
console.log('\ncreateElementNS (with prefix):');
console.log('  name:         ' + child3.name);
console.log('  prefix:       ' + child3.prefix);
console.log('  localName:    ' + child3.localName);
console.log('  namespaceURI: ' + child3.namespaceURI);
@tmpvar
Copy link
Member

tmpvar commented Jan 23, 2011

this is fixed in the latest head (3261f85)

@tmpvar tmpvar closed this as completed Jun 19, 2011
@akhabibullina
Copy link

Hi!
I use jsdom v0.10.6 and node v0.10.16 and I still experience this problem See more details below.
CODE:

// Create a basic document with empty <head> and <body> tags; DOM level 3.

html5  = require('html5');
window = jsdom.jsdom().createWindow(null, null, {parser: html5});
document = window.document;

var child1 = document.createElement('foo');
var node = document.createElement("p");
node.setAttribute("id", "anna");
child1.appendChild(node);
console.log('createElement:');
console.log('  name:         ' + child1.name);
console.log('  prefix:       ' + child1.prefix);
console.log('  tagName:      ' + child1.tagName);
console.log('  localName:    ' + child1.localName);
console.log('  namespaceURI: ' + child1.namespaceURI);
console.log('  childCount:   ' + child1.childCount);
console.log('  childElementCount:   ' + child1.childElementCount);
console.log('  firstElementChild:   ' + child1.firstElementChild);

// note the value of prefix
var child2 = document.createElementNS('http://example.com', 'foo');
var node = document.createElement("p");
node.setAttribute("id", "anna");
child2.appendChild(node);
console.log('\ncreateElementNS (no prefix):');
console.log('  name:         ' + child2.name);
console.log('  prefix:       ' + child2.prefix);
console.log('  tagName:      ' + child2.tagName);
console.log('  localName:    ' + child2.localName);
console.log('  namespaceURI: ' + child2.namespaceURI);
console.log('  childCount:   ' + child2.childCount);
console.log('  childElementCount:   ' + child2.childElementCount);
console.log('  firstElementChild:   ' + child2.firstElementChild);

var child3 = document.createElementNS('http://example.com', 'foo:bar');
var node = document.createElement("p");
node.setAttribute("id", "anna");
child3.appendChild(node);
console.log('\ncreateElementNS (with prefix):');
console.log('  name:         ' + child3.name);
console.log('  prefix:       ' + child3.prefix);
console.log('  tagName:      ' + child3.localName);
console.log('  localName:    ' + child3.tagName);
console.log('  namespaceURI: ' + child3.namespaceURI);
console.log('  childCount:   ' + child3.childCount);
console.log('  childElementCount:   ' + child3.childElementCount);
console.log('  firstElementChild:   ' + child3.firstElementChild);

OUTPUT:

createElement:
  name:         undefined
  prefix:       null
  tagName:      FOO
  localName:    null
  namespaceURI: null
  childCount:   undefined
  childElementCount:   undefined
  firstElementChild:   undefined

createElementNS (no prefix):
  name:         undefined
  prefix:       null
  tagName:      FOO
  localName:    foo
  namespaceURI: http://example.com
  childCount:   undefined
  childElementCount:   undefined
  firstElementChild:   undefined

createElementNS (with prefix):
  name:         undefined
  prefix:       foo
  tagName:      bar
  localName:    FOO:BAR
  namespaceURI: http://example.com
  childCount:   undefined
  childElementCount:   undefined
  firstElementChild:   undefined

NOTES:
A lot of values are undefined. It is kind of weird. Can anybody help why this happens?

Thanks,
Anna.

@domenic
Copy link
Member

domenic commented Jun 10, 2014

Many of the undefined values are simply parts of the latest DOM spec that jsdom has not implemented.

I don't see the problem with prefixes though. Your no prefix example has no prefix, and your prefix example does.

@akhabibullina
Copy link

Hi Domenic, thank you for response.
I actually need all of the properties :) Ok, we will figure out how to add/set the properties we miss inside our unit test environment.
Anna.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants