Skip to content

Commit

Permalink
feat: add check testUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Jul 14, 2017
1 parent 3087e90 commit 6f53279
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"globals": {
"describe": true,
"it": true,
"xit": true,
"before": true,
"beforeEach": true,
"after": true,
Expand Down
31 changes: 31 additions & 0 deletions test/testutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,35 @@ testUtils.shadowSupport = (function(document) {

})(document);

testUtils.fixtureSetup = function (content) {
'use strict';
var fixture = document.querySelector('#fixture');
if (typeof content === 'string') {
fixture.innerHTML = content;
} else if (content instanceof Node) {
fixture.appendChild(content);
}
axe._tree = axe.utils.getFlattenedTree(fixture);
return fixture;
};

/**
* Create check arguments
*
* @param Node|String Stuff to go into the fixture (html or node)
* @param Object Options argument for the check (optional, default: {})
* @param String Target for the check, CSS selector (default: '#target')
*/
testUtils.checkSetup = function (content, options, target) {
'use strict';
// Normalize the params
if (typeof options !== 'object') {
target = options;
options = {};
}
testUtils.fixtureSetup(content);
var node = axe.utils.querySelectorAll(axe._tree[0], target || '#target')[0];
return [node.actualNode, options, node];
};

axe.testUtils = testUtils;

0 comments on commit 6f53279

Please sign in to comment.