[jest-axe] Fix toHaveNoViolations matcher (#39174)

* [jest-axe] Run Prettier

* [jest-axe] Fix toHaveNoViolations matcher

Jest matchers need to return the type of the thing they're matching.
This commit is contained in:
erbridge
2019-10-22 15:13:51 -07:00
committed by Wesley Wigham
parent 64ebf87ce5
commit 7d9f336bf9
2 changed files with 13 additions and 10 deletions
+5 -7
View File
@@ -1,12 +1,13 @@
// Type definitions for jest-axe 2.2
// Type definitions for jest-axe 3.2
// Project: https://github.com/nickcolley/jest-axe
// Definitions by: Josh Goldberg <https://github.com/JoshuaKGoldberg>
// erbridge <https://github.com/erbridge>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
/// <reference types="jest" />
import { AxeResults, Result, RunOnly } from "axe-core";
import { AxeResults, Result, RunOnly } from 'axe-core';
/**
* Version of the aXe verifier with defaults set.
@@ -34,10 +35,7 @@ export interface AxeOptions {
* @param options Options to run aXe.
* @returns Promise for the results of running aXe.
*/
export type JestAxe = (
html: Element | string,
options?: AxeOptions,
) => Promise<AxeResults>;
export type JestAxe = (html: Element | string, options?: AxeOptions) => Promise<AxeResults>;
/**
* Creates a new aXe verifier function.
@@ -82,7 +80,7 @@ export const toHaveNoViolations: {
declare global {
namespace jest {
interface Matchers<R> {
toHaveNoViolations: IToHaveNoViolations;
toHaveNoViolations(): R;
}
}
+8 -3
View File
@@ -1,4 +1,4 @@
import { configureAxe, axe, toHaveNoViolations, JestAxe } from "jest-axe";
import { configureAxe, axe, toHaveNoViolations, JestAxe } from 'jest-axe';
expect.extend(toHaveNoViolations);
@@ -9,12 +9,17 @@ const newJestWithOptions: JestAxe = configureAxe({
iframes: false,
rules: {},
runOnly: {
type: "rules",
type: 'rules',
},
selectors: false,
});
const sameJest: JestAxe = axe;
expect("").toHaveNoViolations();
expect('').toHaveNoViolations();
expect(document.body).toHaveNoViolations();
async () => {
expect(await Promise.resolve(document.body)).toHaveNoViolations();
await expect(Promise.resolve(document.body)).resolves.toHaveNoViolations();
};