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

Comparing attributes gives 'nodeType is unexpected' error #22

Open
jasny opened this issue Feb 14, 2017 · 1 comment · May be fixed by #24
Open

Comparing attributes gives 'nodeType is unexpected' error #22

jasny opened this issue Feb 14, 2017 · 1 comment · May be fixed by #24

Comments

@jasny
Copy link

jasny commented Feb 14, 2017

When comparing attributes, I get the error

Error: nodeValue is not equal, but nodeType is unexpected
    at Collector.collectFailure (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/collector.js:113:34)
    at Comparator._compareAttributes (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:74:36)
    at Comparator.compareNode (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:108:28)
    at Comparator._compareNodeList (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:36:23)
    at Comparator.compareNode (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:109:27)
    at Comparator._compareNodeList (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:36:23)
    at Comparator.compareNode (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:109:27)
    at Comparator.compareNode (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:106:28)
    at module.exports (/home/arnold/Projects/legalthings/legalform-js/node_modules/dom-compare/lib/compare.js:137:18)
    at Object.<anonymous> (/home/arnold/Projects/legalthings/legalform-js/dom-compare-tests.js:10:14)
var compare = require('dom-compare').compare;
var jsdom = require('jsdom');

// Those are the HTML fragments that we want to compare:
var expectedHTML = '<div class="foo"></div>';
var actualHTML = '<div class="bar"></div>';

var expectedDOM = jsdom.jsdom(expectedHTML);
var actualDOM = jsdom.jsdom(actualHTML);
var result = compare(expectedDOM, actualDOM);

console.log('diff array:', result.getDifferences());

I've dumped the actual and expected variables in collector.js and noticed they don't seem to have any properties.

console.log(expected, actual, vExpected, vActual);

yields

Attr {} Attr {} 'foo' 'bar'
@chiptus
Copy link

chiptus commented Apr 26, 2017

that's a bug in jsdom. Attr is not inherting Node and thus they don't have nodeType. we can add a quickfix that if nodeType is undefined will compare classes.

@chiptus chiptus linked a pull request Apr 26, 2017 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants