Skip to content

Commit

Permalink
fix: support new vitest typings
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed May 4, 2023
1 parent bd3a7d0 commit fce32a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@types/node": "^18.16.3",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"@vitest/expect": "^0.31.0",
"esbuild": "^0.17.18",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions src/vitest/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ import { afterEach, beforeEach, expect } from 'vitest';

import { register as __register, toBeAnnounced } from '../to-be-announced';

interface ToBeAnnouncedMatchers {
interface ToBeAnnouncedMatchers<T = any> {
/**
* Assert whether given message was announced by ARIA live region.
*
* @param politenessSetting `POLITENESS_SETTING` of the announcement
*/
toBeAnnounced(politenessSetting?: Exclude<PolitenessSetting, 'off'>): void;
toBeAnnounced(politenessSetting?: Exclude<PolitenessSetting, 'off'>): T;
}

declare module '@vitest/expect' {
interface Assertion<T> extends ToBeAnnouncedMatchers<T> {}
}

// For Vitest below 0.31.x
declare global {
namespace Vi {
interface Assertion extends ToBeAnnouncedMatchers {}
interface Assertion<T> extends ToBeAnnouncedMatchers<T> {}
}
}

expect.extend({ toBeAnnounced });
(expect as any).extend({ toBeAnnounced });

/**
* Register `extend-to-be-expected` to track DOM nodes
Expand Down

0 comments on commit fce32a9

Please sign in to comment.