mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
[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:
Vendored
+5
-7
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user