forked from baruchvlz/resq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (23 loc) · 872 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import ReactSelectorQuery from './src/resq'
import { waitToLoadReact } from './src/waitToLoadReact'
import { findReactInstance } from './src/utils'
function doQuery(selector, method, element) {
if (!element && !global.isReactLoaded) {
throw new Error('Could not find the root element of your application')
}
let reactInstance = global.rootReactElement
if (element instanceof HTMLElement) {
reactInstance = findReactInstance(element)
}
if (!reactInstance) {
throw new Error('Could not find instance of React in given element')
}
return new ReactSelectorQuery(selector, reactInstance)[method]()
}
export function resq$(selector, element) {
return doQuery(selector, 'find', element)
}
export function resq$$(selector, element) {
return doQuery(selector, 'findAll', element)
}
export { waitToLoadReact }