forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): add function
isXHTML
to test if a document node is XHTML
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); |