Skip to content

Commit

Permalink
feat(utils): add function isXHTML to test if a document node is XHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeltour committed Dec 15, 2017
1 parent d4b0900 commit 701f72f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/core/utils/is-xhtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

/**
* Determines if a document node is XHTML
* @method isXHTML
* @memberof axe.utils
* @instance
* @param {Node} doc a document node
* @return {Boolean}
*/
axe.utils.isXHTML = function (doc) {
'use strict';
if (!doc.createElement) {
return false;
}
return doc.createElement('A').localName === 'A';
};
21 changes: 21 additions & 0 deletions test/core/utils/is-xhtml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
describe('axe.utils.isXHTML', function () {
'use strict';

it('should be a function', function () {
assert.isFunction(axe.utils.isXHTML);
});

it('should return true on any document that is XHTML', function () {
var doc = document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'html', null);
assert.isTrue(axe.utils.isXHTML(doc));
});

it('should return false on any document that is HTML', function () {
var doc = document.implementation.createHTMLDocument('Monkeys');
assert.isFalse(axe.utils.isXHTML(doc));
});

it('should return false on any document that is HTML - fixture', function () {
assert.isFalse(axe.utils.isXHTML(document));
});
});

0 comments on commit 701f72f

Please sign in to comment.