UNPKG

@axe-core/cli

Version:

A CLI for accessibility testing using axe-core

73 lines 3.35 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); require("mocha"); const chai_1 = require("chai"); const axe_test_urls_1 = __importDefault(require("./axe-test-urls")); describe('testPages', function () { this.timeout(10000); let config; let mockDriver; beforeEach(() => { const func = (arg) => __awaiter(this, void 0, void 0, function* () { return '{}'; }); mockDriver = { get: func, executeAsyncScript: func, executeScript: func, wait: func, switchTo: () => ({ defaultContent: () => { } }), findElements: () => __awaiter(this, void 0, void 0, function* () { return []; }), quit: func, manage: () => ({ setTimeouts: func }) }; config = { driver: mockDriver }; }); it('return a promise', () => { chai_1.assert.instanceOf((0, axe_test_urls_1.default)([], config), Promise); }); it('calls driver.get() for each URL', () => __awaiter(this, void 0, void 0, function* () { const urlsCalled = []; const urls = ['http://foo', 'http://bar', 'http://baz']; mockDriver.get = (url) => __awaiter(this, void 0, void 0, function* () { urlsCalled.push(url); return url; }); yield (0, axe_test_urls_1.default)(urls, config); chai_1.assert.deepEqual(urlsCalled, urls); })); it('injects axe into the page', () => __awaiter(this, void 0, void 0, function* () { const scripts = []; config.axeSource = 'axe="hi, I am axe"'; mockDriver.executeScript = (script) => __awaiter(this, void 0, void 0, function* () { scripts.push(script); return script; }); yield (0, axe_test_urls_1.default)(['http://foo'], config); chai_1.assert.include(scripts[0].toString(), config.axeSource); })); it('runs axe once the page is loaded', () => __awaiter(this, void 0, void 0, function* () { const asyncScripts = []; mockDriver.executeAsyncScript = (script) => __awaiter(this, void 0, void 0, function* () { asyncScripts.push(script); return '{}'; }); yield (0, axe_test_urls_1.default)(['http://foo'], config); chai_1.assert.isDefined(asyncScripts .map(script => script.toString()) .find(script => script.match(/(axe\.run)|(axe\.a11yCheck)/))); })); }); //# sourceMappingURL=axe-test-urls.test.js.map