Skip to content

Commit 2baff57

Browse files
jpavonKent C. Dodds
authored and
Kent C. Dodds
committed
fix(TS): clean up code from index.d.ts (#131)
* clean up code from index.d.ts - export all types from 'dom-testing-library' - use getQueriesForElement to get all GetsAndQueries - remove duplicate code * remove wait and waitForElement * remove non used import * use consistent void return * unmount returns boolean
1 parent 36e1349 commit 2baff57

File tree

1 file changed

+4
-184
lines changed

1 file changed

+4
-184
lines changed

typings/index.d.ts

+4-184
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,14 @@
1-
import {Simulate as ReactSimulate} from 'react-dom/test-utils'
2-
import {
3-
AllByAttribute,
4-
AllByText,
5-
BoundFunction,
6-
GetByAttribute,
7-
GetByText,
8-
QueryByAttribute,
9-
QueryByText,
10-
} from 'dom-testing-library'
11-
export {prettyDOM} from 'dom-testing-library'
1+
import {getQueriesForElement} from 'dom-testing-library'
122

13-
type TextMatchFunction = (content: string, element: HTMLElement) => boolean
14-
type TextMatch = string | RegExp | TextMatchFunction
15-
type TextMatchOptions = {
16-
exact?: boolean
17-
trim?: boolean
18-
collapseWhitespace?: boolean
19-
}
20-
21-
interface GetsAndQueries {
22-
queryByPlaceholderText: BoundFunction<QueryByAttribute>
23-
queryAllByPlaceholderText: BoundFunction<AllByAttribute>
24-
getByPlaceholderText: BoundFunction<GetByAttribute>
25-
getAllByPlaceholderText: BoundFunction<AllByAttribute>
26-
queryByText: BoundFunction<QueryByText>
27-
queryAllByText: BoundFunction<AllByText>
28-
getByText: BoundFunction<GetByText>
29-
getAllByText: BoundFunction<AllByText>
30-
queryByLabelText: BoundFunction<QueryByText>
31-
queryAllByLabelText: BoundFunction<AllByText>
32-
getByLabelText: BoundFunction<GetByText>
33-
getAllByLabelText: BoundFunction<AllByText>
34-
queryByAltText: BoundFunction<QueryByAttribute>
35-
queryAllByAltText: BoundFunction<AllByAttribute>
36-
getByAltText: BoundFunction<GetByAttribute>
37-
getAllByAltText: BoundFunction<AllByAttribute>
38-
queryByTestId: BoundFunction<QueryByAttribute>
39-
queryAllByTestId: BoundFunction<AllByAttribute>
40-
getByTestId: BoundFunction<GetByAttribute>
41-
getAllByTestId: BoundFunction<AllByAttribute>
42-
queryByTitle: BoundFunction<QueryByAttribute>
43-
queryAllByTitle: BoundFunction<AllByAttribute>
44-
getByTitle: BoundFunction<GetByAttribute>
45-
getAllByTitle: BoundFunction<AllByAttribute>
46-
queryByValue: BoundFunction<QueryByAttribute>
47-
queryAllByValue: BoundFunction<AllByAttribute>
48-
getByValue: BoundFunction<GetByAttribute>
49-
getAllByValue: BoundFunction<AllByAttribute>
50-
}
3+
export * from 'dom-testing-library'
514

52-
export const queryByPlaceholderText: QueryByAttribute
53-
export const queryAllByPlaceholderText: AllByAttribute
54-
export const getByPlaceholderText: GetByAttribute
55-
export const getAllByPlaceholderText: AllByAttribute
56-
export const queryByText: QueryByText
57-
export const queryAllByText: AllByText
58-
export const getByText: GetByText
59-
export const getAllByText: AllByText
60-
export const queryByLabelText: QueryByText
61-
export const queryAllByLabelText: AllByText
62-
export const getByLabelText: GetByText
63-
export const getAllByLabelText: AllByText
64-
export const queryByAltText: QueryByAttribute
65-
export const queryAllByAltText: AllByAttribute
66-
export const getByAltText: GetByAttribute
67-
export const getAllByAltText: AllByAttribute
68-
export const queryByTestId: QueryByAttribute
69-
export const queryAllByTestId: AllByAttribute
70-
export const getByTestId: GetByAttribute
71-
export const getAllByTestId: AllByAttribute
72-
export const queryByTitle: QueryByAttribute
73-
export const queryAllByTitle: AllByAttribute
74-
export const getByTitle: GetByAttribute
75-
export const getAllByTitle: AllByAttribute
76-
export const queryByValue: QueryByAttribute
77-
export const queryAllByValue: AllByAttribute
78-
export const getByValue: GetByAttribute
79-
export const getAllByValue: AllByAttribute
5+
type GetsAndQueries = ReturnType<typeof getQueriesForElement>
806

817
export interface RenderResult extends GetsAndQueries {
828
container: HTMLDivElement
839
debug: () => void
8410
rerender: (ui: React.ReactElement<any>) => void
85-
unmount: VoidFunction
11+
unmount: () => boolean
8612
}
8713

8814
/**
@@ -93,113 +19,7 @@ export function render(
9319
options?: {container: HTMLElement; baseElement: HTMLElement},
9420
): RenderResult
9521

96-
/**
97-
* When in need to wait for DOM elements to appear, disappear, or change. Prefer waitForElement.
98-
*/
99-
export function wait(
100-
callback?: () => void,
101-
options?: {
102-
timeout?: number
103-
interval?: number
104-
},
105-
): Promise<void>
106-
107-
/**
108-
* When in need to wait for DOM elements to appear, disappear, or change.
109-
*/
110-
export function waitForElement<T>(
111-
callback?: () => T,
112-
options?: {
113-
container?: HTMLElement
114-
timeout?: number
115-
mutationObserverOptions?: MutationObserverInit
116-
},
117-
): Promise<T | undefined>
118-
119-
type EventType =
120-
| 'copy'
121-
| 'cut'
122-
| 'paste'
123-
| 'compositionEnd'
124-
| 'compositionStart'
125-
| 'compositionUpdate'
126-
| 'keyDown'
127-
| 'keyPress'
128-
| 'keyUp'
129-
| 'focus'
130-
| 'blur'
131-
| 'change'
132-
| 'input'
133-
| 'invalid'
134-
| 'submit'
135-
| 'click'
136-
| 'contextMenu'
137-
| 'dblClick'
138-
| 'drag'
139-
| 'dragEnd'
140-
| 'dragEnter'
141-
| 'dragExit'
142-
| 'dragLeave'
143-
| 'dragOver'
144-
| 'dragStart'
145-
| 'drop'
146-
| 'mouseDown'
147-
| 'mouseEnter'
148-
| 'mouseLeave'
149-
| 'mouseMove'
150-
| 'mouseOut'
151-
| 'mouseOver'
152-
| 'mouseUp'
153-
| 'select'
154-
| 'touchCancel'
155-
| 'touchEnd'
156-
| 'touchMove'
157-
| 'touchStart'
158-
| 'scroll'
159-
| 'wheel'
160-
| 'abort'
161-
| 'canPlay'
162-
| 'canPlayThrough'
163-
| 'durationChange'
164-
| 'emptied'
165-
| 'encrypted'
166-
| 'ended'
167-
| 'loadedData'
168-
| 'loadedMetadata'
169-
| 'loadStart'
170-
| 'pause'
171-
| 'play'
172-
| 'playing'
173-
| 'progress'
174-
| 'rateChange'
175-
| 'seeked'
176-
| 'seeking'
177-
| 'stalled'
178-
| 'suspend'
179-
| 'timeUpdate'
180-
| 'volumeChange'
181-
| 'waiting'
182-
| 'load'
183-
| 'error'
184-
| 'animationStart'
185-
| 'animationEnd'
186-
| 'animationIteration'
187-
| 'transitionEnd'
188-
| 'doubleClick'
189-
190-
type FireFunction = (element: HTMLElement, event: Event) => boolean
191-
type FireObject = {
192-
[K in EventType]: (element: HTMLElement, options?: {}) => boolean
193-
}
194-
195-
/**
196-
* Fire DOM events.
197-
*/
198-
export const fireEvent: FireFunction & FireObject
199-
20022
/**
20123
* Unmounts React trees that were mounted with render.
20224
*/
20325
export function cleanup(): void
204-
205-
export function getQueriesForElement(element: HTMLElement): GetsAndQueries

0 commit comments

Comments
 (0)