0

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?

        });
    });
})
Danyal Aytekin
  • 4,106
  • 3
  • 36
  • 44

1 Answers1

2

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();
    });
  });
});
Matthew Blewitt
  • 459
  • 1
  • 3
  • 15