Guest User

Untitled

a guest
Aug 15th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var jsdom = require('jsdom');
  2.  
  3. // Some html page
  4. var html = [
  5.     '<html>',
  6.         '<body>',
  7.             '<p>An image without an alt tag! <img src="some.jpg" /></p>',
  8.             '<h2>Not an h1</h2>',
  9.             '<h5>blabla</h5>',
  10.             '<h4></h4>',
  11.         '</body>',
  12.     '</html>'
  13. ].join('\n');
  14.  
  15. jsdom.env(html, function(err, window) {
  16.     // Make the `window` object globally available as axe-core assumes a
  17.     // a browser context
  18.     global.window = window;
  19.  
  20.     // Make the `Node` and `NodeList` classes globally available
  21.     global.Node = window.Node;
  22.     global.NodeList = window.NodeList;
  23.  
  24.     // Only now can `axe-core` be required as it checks for the `window`
  25.     // object on module initialization
  26.     // TODO: axe uses `document.createRange` which is not available through `jsdom`
  27.     var axe = require('axe-core');
  28.  
  29.     // Run the checks
  30.     axe.a11yCheck(window.document, function(data) {
  31.         console.log(data);
  32.     });
  33. });
Add Comment
Please, Sign In to add comment