What is the best way to use Pa11y with Supertest? Something like:
describe ('my page', function () {
it ('is accessible', function () {
request (server).get ('/').expect (function ({ body }) {
// How to run Pa11y here?
});
});
})
I would suggest not using supertest
at all for these accessibility test as pa11y
can ping url's directly.
const pa11y = require('pa11y');
const request = require('supertest');
const mocha = require('mocha');
const { expect } = require('chai');
const server = require('./server');
const url =
process.env.NODE_ENV === 'testing'
? 'http://localhost:3000'
: 'http://example.com';
describe('my page', function() {
it('is accessible', function(done) {
pa11y(`${url}/`, function(err, results) {
expect(results.issues).to.be.empty;
done();
});
});
});