File tree 3 files changed +18
-8
lines changed
3 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 1
1
import { Matcher , MatcherOptions , SelectorMatcherOptions } from 'dom-testing-library/typings' // tslint:disable-line no-submodule-imports
2
2
import { getDocument , getQueriesForElement } from '.'
3
+ import { ElementHandle } from '../node_modules/@types/puppeteer'
3
4
4
5
// tslint:disable-next-line
5
6
let Page , ElementHandle
9
10
ElementHandle = require ( 'puppeteer/lib/ElementHandle.js' ) // tslint:disable-line
10
11
11
12
Page . prototype . getDocument = getDocument
12
- getQueriesForElement ( ElementHandle . prototype )
13
+ getQueriesForElement ( ElementHandle . prototype , function ( this : ElementHandle ) : ElementHandle {
14
+ return this
15
+ } )
16
+
17
+ ElementHandle . prototype . getQueriesForElement = function ( this : ElementHandle ) : ElementHandle {
18
+ return getQueriesForElement ( this )
19
+ }
13
20
} catch ( err ) {
14
21
// tslint:disable-next-line
15
22
console . error ( 'Could not augment puppeteer functions, do you have a conflicting version?' )
Original file line number Diff line number Diff line change @@ -118,11 +118,8 @@ export function wait(
118
118
119
119
export function getQueriesForElement < T > ( object : T , contextFn ?: ContextFn ) : T & IQueryUtils {
120
120
const o = object as any
121
- o . getQueriesForElement = function ( ) {
122
- const realContextFn = contextFn || ( ( ) : ElementHandle => this )
123
- return getQueriesForElement ( this , realContextFn )
124
- }
125
-
121
+ if ( ! contextFn ) contextFn = ( ) => o
122
+ o . getQueriesForElement = ( ) => getQueriesForElement ( o , ( ) => o )
126
123
o . queryByPlaceholderText = createDelegateFor ( 'queryByPlaceholderText' , contextFn )
127
124
o . queryAllByPlaceholderText = createDelegateFor ( 'queryAllByPlaceholderText' , contextFn )
128
125
o . getByPlaceholderText = createDelegateFor ( 'getByPlaceholderText' , contextFn )
Original file line number Diff line number Diff line change 1
1
import * as path from 'path'
2
2
import * as puppeteer from 'puppeteer'
3
- import { getDocument , queries } from '../lib'
3
+ import { getDocument , queries , getQueriesForElement } from '../lib'
4
4
5
5
describe ( 'lib/index.ts' , ( ) => {
6
6
let browser : puppeteer . Browser
@@ -15,7 +15,13 @@ describe('lib/index.ts', () => {
15
15
it ( 'should export the utilities' , async ( ) => {
16
16
const document = await getDocument ( page )
17
17
const element = await queries . getByText ( document , 'Hello h1' )
18
- expect ( await page . evaluate ( el => el . textContent , element ) ) . toEqual ( 'Hello h1' )
18
+ expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h1' )
19
+ } )
20
+
21
+ it ( 'should bind getQueriesForElement' , async ( ) => {
22
+ const { getByText} = getQueriesForElement ( await getDocument ( page ) )
23
+ const element = await getByText ( 'Hello h1' )
24
+ expect ( await queries . getNodeText ( element ) ) . toEqual ( 'Hello h1' )
19
25
} )
20
26
21
27
afterAll ( async ( ) => {
You can’t perform that action at this time.
0 commit comments