mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-18 05:02:23 -06:00
fix: prevObject types (#21106)
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com> Co-authored-by: Rachel <rachel@cypress.io> Co-authored-by: Tyler Biethman <tbiethman@users.noreply.github.com>
This commit is contained in:
11
cli/types/cypress.d.ts
vendored
11
cli/types/cypress.d.ts
vendored
@@ -10,10 +10,13 @@ declare namespace Cypress {
|
||||
type PrevSubject = keyof PrevSubjectMap
|
||||
type TestingType = 'e2e' | 'component'
|
||||
type PluginConfig = (on: PluginEvents, config: PluginConfigOptions) => void | ConfigOptions | Promise<ConfigOptions>
|
||||
interface JQueryWithSelector<TElement = HTMLElement> extends JQuery<TElement> {
|
||||
selector?: string | null
|
||||
}
|
||||
|
||||
interface PrevSubjectMap<O = unknown> {
|
||||
optional: O
|
||||
element: JQuery
|
||||
element: JQueryWithSelector
|
||||
document: Document
|
||||
window: Window
|
||||
}
|
||||
@@ -467,16 +470,18 @@ declare namespace Cypress {
|
||||
Commands: {
|
||||
add<T extends keyof Chainable>(name: T, fn: CommandFn<T>): void
|
||||
add<T extends keyof Chainable>(name: T, options: CommandOptions & {prevSubject: false}, fn: CommandFn<T>): void
|
||||
add<T extends keyof Chainable, S = any>(name: T, options: CommandOptions & {prevSubject: true}, fn: CommandFnWithSubject<T, S>): void
|
||||
add<T extends keyof Chainable, S extends PrevSubject>(
|
||||
name: T, options: CommandOptions & { prevSubject: true | S | ['optional'] }, fn: CommandFnWithSubject<T, PrevSubjectMap[S]>,
|
||||
name: T, options: CommandOptions & { prevSubject: S | ['optional'] }, fn: CommandFnWithSubject<T, PrevSubjectMap[S]>,
|
||||
): void
|
||||
add<T extends keyof Chainable, S extends PrevSubject>(
|
||||
name: T, options: CommandOptions & { prevSubject: S[] }, fn: CommandFnWithSubject<T, PrevSubjectMap<void>[S]>,
|
||||
): void
|
||||
addAll<T extends keyof Chainable>(fns: CommandFns): void
|
||||
addAll<T extends keyof Chainable>(options: CommandOptions & {prevSubject: false}, fns: CommandFns): void
|
||||
addAll<T extends keyof Chainable, S = any>(options: CommandOptions & { prevSubject: true }, fns: CommandFnsWithSubject<S>): void
|
||||
addAll<T extends keyof Chainable, S extends PrevSubject>(
|
||||
options: CommandOptions & { prevSubject: true | S | ['optional'] }, fns: CommandFnsWithSubject<PrevSubjectMap[S]>,
|
||||
options: CommandOptions & { prevSubject: S | ['optional'] }, fns: CommandFnsWithSubject<PrevSubjectMap[S]>,
|
||||
): void
|
||||
addAll<T extends keyof Chainable, S extends PrevSubject>(
|
||||
options: CommandOptions & { prevSubject: S[] }, fns: CommandFnsWithSubject<PrevSubjectMap<void>[S]>,
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace CypressCommandsTests {
|
||||
arg // $ExpectType string
|
||||
})
|
||||
Cypress.Commands.add('newCommand', { prevSubject: true }, (subject, arg) => {
|
||||
subject // $ExpectType unknown
|
||||
subject // $ExpectType any
|
||||
arg // $ExpectType string
|
||||
return
|
||||
})
|
||||
@@ -113,11 +113,11 @@ namespace CypressCommandsTests {
|
||||
arg // $ExpectType string
|
||||
})
|
||||
Cypress.Commands.add('newCommand', { prevSubject: 'element' }, (subject, arg) => {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
arg // $ExpectType string
|
||||
})
|
||||
Cypress.Commands.add('newCommand', { prevSubject: ['element'] }, (subject, arg) => {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
arg // $ExpectType string
|
||||
})
|
||||
Cypress.Commands.add('newCommand', { prevSubject: ['element', 'document', 'window'] }, (subject, arg) => {
|
||||
@@ -126,7 +126,7 @@ namespace CypressCommandsTests {
|
||||
} else if (subject instanceof Document) {
|
||||
subject // $ExpectType Document
|
||||
} else {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
}
|
||||
arg // $ExpectType string
|
||||
})
|
||||
@@ -136,7 +136,7 @@ namespace CypressCommandsTests {
|
||||
} else if (subject instanceof Document) {
|
||||
subject // $ExpectType Document
|
||||
} else if (subject) {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
} else {
|
||||
subject // $ExpectType void
|
||||
}
|
||||
@@ -173,7 +173,7 @@ namespace CypressCommandsTests {
|
||||
})
|
||||
Cypress.Commands.addAll({ prevSubject: true }, {
|
||||
newCommand: (subject, arg) => {
|
||||
subject // $ExpectType unknown
|
||||
subject // $ExpectType any
|
||||
arg // $ExpectType any
|
||||
return
|
||||
},
|
||||
@@ -215,13 +215,13 @@ namespace CypressCommandsTests {
|
||||
})
|
||||
Cypress.Commands.addAll({ prevSubject: 'element' }, {
|
||||
newCommand: (subject, arg) => {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
arg // $ExpectType any
|
||||
}
|
||||
})
|
||||
Cypress.Commands.addAll({ prevSubject: ['element'] }, {
|
||||
newCommand: (subject, arg) => {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
arg // $ExpectType any
|
||||
}
|
||||
})
|
||||
@@ -232,7 +232,7 @@ namespace CypressCommandsTests {
|
||||
} else if (subject instanceof Document) {
|
||||
subject // $ExpectType Document
|
||||
} else {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
}
|
||||
arg // $ExpectType any
|
||||
}
|
||||
@@ -244,7 +244,7 @@ namespace CypressCommandsTests {
|
||||
} else if (subject instanceof Document) {
|
||||
subject // $ExpectType Document
|
||||
} else if (subject) {
|
||||
subject // $ExpectType JQuery<HTMLElement>
|
||||
subject // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
} else {
|
||||
subject // $ExpectType void
|
||||
}
|
||||
@@ -271,7 +271,7 @@ namespace CypressCommandsTests {
|
||||
originalFn.apply(this, [arg]) // $ExpectType Chainable<number>
|
||||
})
|
||||
Cypress.Commands.overwrite<'type', 'element'>('type', (originalFn, element, text, options?: Partial<Cypress.TypeOptions & {sensitive: boolean}>) => {
|
||||
element // $ExpectType JQuery<HTMLElement>
|
||||
element // $ExpectType JQueryWithSelector<HTMLElement>
|
||||
text // $ExpectType string
|
||||
|
||||
if (options && options.sensitive) {
|
||||
|
||||
Reference in New Issue
Block a user