Skip to content

Commit 0960143

Browse files
committed
refactor: move types to proper places
1 parent 9ab40e0 commit 0960143

File tree

3 files changed

+62
-59
lines changed

3 files changed

+62
-59
lines changed

lib/extend.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Matcher, MatcherOptions, SelectorMatcherOptions} from 'dom-testing-library/typings' // tslint:disable-line no-submodule-imports
12
import {extendObjectWithTestingUtils, getDocument} from '.'
23

34
const Page = require('puppeteer/lib/Page.js') // tslint:disable-line
@@ -6,3 +7,37 @@ const ElementHandle = require('puppeteer/lib/ElementHandle.js') // tslint:disabl
67
Page.prototype.document = getDocument
78

89
extendObjectWithTestingUtils(ElementHandle.prototype)
10+
11+
/* tslint:disable */
12+
declare module 'puppeteer' {
13+
interface Page {
14+
document(): Promise<ElementHandle>
15+
}
16+
17+
interface ElementHandle {
18+
queryByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
19+
queryAllByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
20+
getByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
21+
getAllByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
22+
queryByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle | null>
23+
queryAllByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
24+
getByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle>
25+
getAllByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
26+
queryByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle | null>
27+
queryAllByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
28+
getByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle>
29+
getAllByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
30+
queryByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
31+
queryAllByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
32+
getByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
33+
getAllByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
34+
queryByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
35+
queryAllByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
36+
getByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
37+
getAllByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
38+
queryByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
39+
queryAllByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
40+
getByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
41+
getAllByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
42+
}
43+
}

lib/index.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,33 @@ export async function getDocument(context?: Page): Promise<ElementHandle> {
6161
return document
6262
}
6363

64-
export function extendObjectWithTestingUtils(object: any, contextFn?: ContextFn): void {
65-
object.queryByPlaceholderText = createDelegateFor('queryByPlaceholderText', contextFn)
66-
object.queryAllByPlaceholderText = createDelegateFor('queryAllByPlaceholderText', contextFn)
67-
object.getByPlaceholderText = createDelegateFor('getByPlaceholderText', contextFn)
68-
object.getAllByPlaceholderText = createDelegateFor('getAllByPlaceholderText', contextFn)
69-
object.queryByText = createDelegateFor('queryByText', contextFn)
70-
object.queryAllByText = createDelegateFor('queryAllByText', contextFn)
71-
object.getByText = createDelegateFor('getByText', contextFn)
72-
object.getAllByText = createDelegateFor('getAllByText', contextFn)
73-
object.queryByLabelText = createDelegateFor('queryByLabelText', contextFn)
74-
object.queryAllByLabelText = createDelegateFor('queryAllByLabelText', contextFn)
75-
object.getByLabelText = createDelegateFor('getByLabelText', contextFn)
76-
object.getAllByLabelText = createDelegateFor('getAllByLabelText', contextFn)
77-
object.queryByAltText = createDelegateFor('queryByAltText', contextFn)
78-
object.queryAllByAltText = createDelegateFor('queryAllByAltText', contextFn)
79-
object.getByAltText = createDelegateFor('getByAltText', contextFn)
80-
object.getAllByAltText = createDelegateFor('getAllByAltText', contextFn)
81-
object.queryByTestId = createDelegateFor('queryByTestId', contextFn)
82-
object.queryAllByTestId = createDelegateFor('queryAllByTestId', contextFn)
83-
object.getByTestId = createDelegateFor('getByTestId', contextFn)
84-
object.getAllByTestId = createDelegateFor('getAllByTestId', contextFn)
85-
object.queryByTitle = createDelegateFor('queryByTitle', contextFn)
86-
object.queryAllByTitle = createDelegateFor('queryAllByTitle', contextFn)
87-
object.getByTitle = createDelegateFor('getByTitle', contextFn)
88-
object.getAllByTitle = createDelegateFor('getAllByTitle', contextFn)
64+
export function extendObjectWithTestingUtils<T>(object: T, contextFn?: ContextFn): T & ITestUtils {
65+
const o = object as any
66+
o.queryByPlaceholderText = createDelegateFor('queryByPlaceholderText', contextFn)
67+
o.queryAllByPlaceholderText = createDelegateFor('queryAllByPlaceholderText', contextFn)
68+
o.getByPlaceholderText = createDelegateFor('getByPlaceholderText', contextFn)
69+
o.getAllByPlaceholderText = createDelegateFor('getAllByPlaceholderText', contextFn)
70+
o.queryByText = createDelegateFor('queryByText', contextFn)
71+
o.queryAllByText = createDelegateFor('queryAllByText', contextFn)
72+
o.getByText = createDelegateFor('getByText', contextFn)
73+
o.getAllByText = createDelegateFor('getAllByText', contextFn)
74+
o.queryByLabelText = createDelegateFor('queryByLabelText', contextFn)
75+
o.queryAllByLabelText = createDelegateFor('queryAllByLabelText', contextFn)
76+
o.getByLabelText = createDelegateFor('getByLabelText', contextFn)
77+
o.getAllByLabelText = createDelegateFor('getAllByLabelText', contextFn)
78+
o.queryByAltText = createDelegateFor('queryByAltText', contextFn)
79+
o.queryAllByAltText = createDelegateFor('queryAllByAltText', contextFn)
80+
o.getByAltText = createDelegateFor('getByAltText', contextFn)
81+
o.getAllByAltText = createDelegateFor('getAllByAltText', contextFn)
82+
o.queryByTestId = createDelegateFor('queryByTestId', contextFn)
83+
o.queryAllByTestId = createDelegateFor('queryAllByTestId', contextFn)
84+
o.getByTestId = createDelegateFor('getByTestId', contextFn)
85+
o.getAllByTestId = createDelegateFor('getAllByTestId', contextFn)
86+
o.queryByTitle = createDelegateFor('queryByTitle', contextFn)
87+
o.queryAllByTitle = createDelegateFor('queryAllByTitle', contextFn)
88+
o.getByTitle = createDelegateFor('getByTitle', contextFn)
89+
o.getAllByTitle = createDelegateFor('getAllByTitle', contextFn)
90+
return o
8991
}
9092

9193
// @ts-ignore

lib/typedefs.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,3 @@ export interface ITestUtils {
2929
getByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element>
3030
getAllByTitle(el: Element, m: Matcher, opts?: MatcherOptions): Promise<Element[]>
3131
}
32-
33-
/* tslint:disable */
34-
declare module 'puppeteer' {
35-
interface Page {
36-
document(): Promise<ElementHandle>
37-
}
38-
39-
interface ElementHandle {
40-
queryByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
41-
queryAllByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
42-
getByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
43-
getAllByPlaceholderText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
44-
queryByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle | null>
45-
queryAllByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
46-
getByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle>
47-
getAllByText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
48-
queryByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle | null>
49-
queryAllByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
50-
getByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle>
51-
getAllByLabelText(m: Matcher, opts?: SelectorMatcherOptions): Promise<ElementHandle[]>
52-
queryByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
53-
queryAllByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
54-
getByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
55-
getAllByAltText(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
56-
queryByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
57-
queryAllByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
58-
getByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
59-
getAllByTestId(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
60-
queryByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle | null>
61-
queryAllByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
62-
getByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle>
63-
getAllByTitle(m: Matcher, opts?: MatcherOptions): Promise<ElementHandle[]>
64-
}
65-
}

0 commit comments

Comments
 (0)