forked from cypress-io/cypress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.ts
39 lines (29 loc) · 1.03 KB
/
jquery.ts
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
32
33
34
35
36
37
38
39
import $ from 'jquery'
import $dom from '../dom'
import $utils from '../cypress/utils'
import type { StateFunc } from '../cypress/state'
const remoteJQueryisNotSameAsGlobal = (remoteJQuery) => {
return remoteJQuery && (remoteJQuery !== $)
}
// eslint-disable-next-line @cypress/dev/arrow-body-multiline-braces
export const create = (state: StateFunc) => ({
$$ (selector, context) {
if (context == null) {
context = state('document')
}
return $dom.query(selector, context)
},
getRemotejQueryInstance (subject) {
// we make assumptions that you cannot have
// an array of mixed types, so we only look at
// the first item (if there's an array)
const firstSubject = $utils.unwrapFirst(subject)
if (!$dom.isElement(firstSubject)) return
const remoteJQuery = state('jQuery') || state('window').$
if (remoteJQueryisNotSameAsGlobal(remoteJQuery)) {
const remoteSubject = remoteJQuery(subject)
return remoteSubject
}
},
})
export interface IJQuery extends ReturnType<typeof create> {}