Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/a11ytester / src / __tests__ / tester.spec.js
Size: Mime:
jest.mock('../pa11yTester');

const { runTests } = require('../tester');
const pa11yTester = require('../pa11yTester');

describe('tester', () => {
  beforeEach(() => {
    jest.resetAllMocks();
    jest.spyOn(pa11yTester, 'test').mockImplementation(() => ({}));
    jest.spyOn(pa11yTester, 'reportCount').mockImplementation(() => ({
      errors: 0,
      warnings: 0,
      notices: 0
    }));
    console.log = jest.fn();
  });

  describe('.runTests()', () => {
    it('runs setup of each test', async () => {
      const fakeTest = {
        setup: jest.fn(),
        cleanup: jest.fn(),
        id: 'fakeTest',
        url: 'https://example.com',
        config: {}
      };
      const fakeTest2 = {
        setup: jest.fn(),
        cleanup: jest.fn(),
        id: 'fakeTest2',
        url: 'https://example.com',
        config: {}
      };

      await runTests([
        fakeTest,
        fakeTest2
      ]);

      expect(pa11yTester.test).toHaveBeenCalledWith(fakeTest);
      expect(pa11yTester.test).toHaveBeenCalledWith(fakeTest2);
    });

    it('runs in order the setup method, then the test, then the cleanup method', async () => {
      const fakeTest = {
        setup: jest.fn().mockImplementation(() => {
          expect(fakeTest.cleanup).not.toHaveBeenCalled();
          expect(pa11yTester.test).not.toHaveBeenCalled();
        }),
        cleanup: jest.fn().mockImplementation(() => {
          expect(fakeTest.setup).toHaveBeenCalled();
          expect(pa11yTester.test).toHaveBeenCalled();
        }),
        id: 'fakeTest',
        url: 'https://example.com',
        config: {}
      };

      await runTests([
        fakeTest
      ]);

      expect(fakeTest.setup).toHaveBeenCalled();
    });
  });
});