diff --git a/CHANGELOG.md b/CHANGELOG.md index 051223fb642..ef7963857e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fixed `EuiComboBox` always showing a scrollbar ([#3744](https://github.com/elastic/eui/pull/3744)) - Replaced `react-focus-lock` with `react-focus-on` ([#3631](https://github.com/elastic/eui/pull/3631)) - Fixed errors in `EuiSuperDatePicker` related to invalid and `null` date formatting ([#3750](https://github.com/elastic/eui/pull/3750)) +- Fixed type definitions for `findTestSubject` and `takeMountedSnapshot` ([#3763](https://github.com/elastic/eui/pull/3763)) ## [`27.1.0`](https://github.com/elastic/eui/tree/v27.1.0) diff --git a/src/test/find_test_subject.ts b/src/test/find_test_subject.ts index 020ff7c27b2..4ea93bea4e6 100644 --- a/src/test/find_test_subject.ts +++ b/src/test/find_test_subject.ts @@ -19,12 +19,6 @@ import { ReactWrapper, ShallowWrapper } from 'enzyme'; -type FindTestSubject = ( - mountedComponent: T, - testSubjectSelector: string, - matcher?: '=' | '~=' | '|=' | '^=' | '$=' | '*=' -) => ReturnType; - /** * Find node which matches a specific test subject selector. Returns ReactWrappers around DOM element, * https://github.com/airbnb/enzyme/tree/master/docs/api/ReactWrapper. @@ -42,13 +36,17 @@ const MATCHERS = [ '^=', // Begins with substring '$=', // Ends with substring '*=', // Contains substring -]; +] as const; + +type FindTestSubject = ( + mountedComponent: T, + testSubjectSelector: string, + matcher?: typeof MATCHERS[number] +) => ReturnType; -export const findTestSubject: FindTestSubject = ( - mountedComponent, - testSubjectSelector, - matcher = '~=' -) => { +export const findTestSubject: FindTestSubject< + ShallowWrapper | ReactWrapper +> = (mountedComponent, testSubjectSelector, matcher = '~=') => { if (!MATCHERS.includes(matcher)) { throw new Error( `Matcher ${matcher} not found in list of allowed matchers: ${MATCHERS.join( diff --git a/src/test/take_mounted_snapshot.ts b/src/test/take_mounted_snapshot.ts index a845b81b4e8..e0cbee8f64a 100644 --- a/src/test/take_mounted_snapshot.ts +++ b/src/test/take_mounted_snapshot.ts @@ -31,7 +31,7 @@ interface TakeMountedSnapshotOptions { * leaving only HTML elements in the snapshot. */ export const takeMountedSnapshot = ( - mountedComponent: ReactWrapper<{}, {}, Component>, + mountedComponent: ReactWrapper, options: TakeMountedSnapshotOptions = {} ) => { const opts: TakeMountedSnapshotOptions = {