Skip to content

Commit f105266

Browse files
WilcoFiersstraker
authored andcommitted
fix(d.ts): RawNodesResult issues (#4229)
* fix(d.ts): RawNodesResult issues * Type tests * More * empty * Fixed feedback
1 parent 8c68546 commit f105266

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

axe.d.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Type definitions for axe-core
22
// Project: https://github.com/dequelabs/axe-core
3-
// Definitions by: Marcy Sutton <https://github.com/marcysutton>
43

54
declare namespace axe {
65
type ImpactValue = 'minor' | 'moderate' | 'serious' | 'critical' | null;
@@ -333,6 +332,14 @@ declare namespace axe {
333332
xpath: string[];
334333
ancestry: UnlabelledFrameSelector;
335334
}
335+
interface DqElement extends SerialDqElement {
336+
element: Element;
337+
toJSON(): SerialDqElement;
338+
mergeSpecs(
339+
childSpec: SerialDqElement,
340+
parentSpec: SerialDqElement
341+
): SerialDqElement;
342+
}
336343
interface PartialRuleResult {
337344
id: string;
338345
result: 'inapplicable';
@@ -351,16 +358,21 @@ declare namespace axe {
351358
frameContext: FrameContextObject;
352359
}
353360

361+
interface RawCheckResult extends Omit<CheckResult, 'relatedNodes'> {
362+
relatedNodes?: Array<SerialDqElement | DqElement>;
363+
}
364+
354365
interface RawNodeResult<T extends 'passed' | 'failed' | 'incomplete'> {
355-
any: CheckResult[];
356-
all: CheckResult[];
357-
none: CheckResult[];
366+
node: SerialDqElement | DqElement;
367+
any: RawCheckResult[];
368+
all: RawCheckResult[];
369+
none: RawCheckResult[];
358370
impact: ImpactValue | null;
359371
result: T;
360372
}
361373

362374
interface RawResult extends Omit<Result, 'nodes'> {
363-
inapplicable: [];
375+
inapplicable: Array<never>;
364376
passes: RawNodeResult<'passed'>[];
365377
incomplete: RawNodeResult<'incomplete'>[];
366378
violations: RawNodeResult<'failed'>[];
@@ -383,6 +395,7 @@ declare namespace axe {
383395
attr(attr: string): string | null;
384396
hasAttr(attr: string): boolean;
385397
props: { [key: string]: unknown };
398+
boundingClientRect: DOMRect;
386399
}
387400

388401
interface Utils {
@@ -396,7 +409,7 @@ declare namespace axe {
396409
DqElement: new (
397410
elm: Element,
398411
options?: { absolutePaths?: boolean }
399-
) => SerialDqElement;
412+
) => DqElement;
400413
uuid: (
401414
options?: { random?: Uint8Array | Array<number> },
402415
buf?: Uint8Array | Array<number>,

typings/axe-core/axe-core-tests.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,44 @@ axe.configure({
344344
}
345345
});
346346

347+
const results: axe.RawResult[] = [
348+
{
349+
id: 'the-best-rule',
350+
result: 'passed',
351+
pageLevel: false,
352+
impact: null,
353+
tags: ['best-practice'],
354+
description: 'Be cool',
355+
help: 'No, cooler',
356+
helpUrl:
357+
'https://dequeuniversity.com/rules/axe/4.8/the-best-rule?application=axeAPI',
358+
inapplicable: [],
359+
passes: [
360+
{
361+
any: [
362+
{
363+
id: 'the-best-check',
364+
data: null,
365+
impact: 'serious',
366+
message: 'Element has sufficient color contrast of 21',
367+
relatedNodes: [
368+
new axe.utils.DqElement(document.body),
369+
new axe.utils.DqElement(document.body).toJSON()
370+
]
371+
}
372+
],
373+
all: [],
374+
none: [],
375+
impact: null,
376+
result: 'passed',
377+
node: new axe.utils.DqElement(document.body)
378+
}
379+
],
380+
incomplete: [],
381+
violations: []
382+
}
383+
];
384+
347385
// Reporters
348386
let fooReporter = (
349387
results: axe.RawResult[],

0 commit comments

Comments
 (0)