Skip to content

Commit 5777be8

Browse files
committed
fix assertions.ts
1 parent 944a0b7 commit 5777be8

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

packages/driver/src/cy/assertions.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-nocheck
2-
31
import _ from 'lodash'
42
import Promise from 'bluebird'
53

@@ -54,12 +52,18 @@ const isDomSubjectAndMatchesValue = (value, subject) => {
5452
return false
5553
}
5654

55+
type Parsed = {
56+
subject?: any
57+
actual?: any
58+
expected?: any
59+
}
60+
5761
// Rules:
5862
// 1. always remove value
5963
// 2. if value is a jquery object set a subject
6064
// 3. if actual is undefined or its not expected remove both actual + expected
6165
const parseValueActualAndExpected = (value, actual, expected) => {
62-
const obj = { actual, expected }
66+
const obj: Parsed = { actual, expected }
6367

6468
if ($dom.isJquery(value)) {
6569
obj.subject = value
@@ -77,7 +81,7 @@ export const create = (Cypress, cy) => {
7781
const getUpcomingAssertions = () => {
7882
const index = cy.state('index') + 1
7983

80-
const assertions = []
84+
const assertions: any[] = []
8185

8286
// grab the rest of the queue'd commands
8387
for (let cmd of cy.queue.slice(index)) {
@@ -137,7 +141,11 @@ export const create = (Cypress, cy) => {
137141
message = message.replace(stackTracesRe, '\n')
138142
}
139143

140-
let obj = parseValueActualAndExpected(value, actual, expected)
144+
let parsed = parseValueActualAndExpected(value, actual, expected)
145+
// TODO: make it more specific after defining the type for Cypress.log().
146+
let obj: Record<string, any> = {
147+
...parsed,
148+
}
141149

142150
if ($dom.isElement(value)) {
143151
obj.$el = $dom.wrap(value)
@@ -216,10 +224,18 @@ export const create = (Cypress, cy) => {
216224
})
217225
}
218226

227+
type VerifyUpcomingAssertionsCallbacks = {
228+
ensureExistenceFor?: 'subject' | 'dom' | boolean
229+
onPass?: Function
230+
onFail?: (err?, isDefaultAssertionErr?: boolean, cmds?: any[]) => void
231+
onRetry?: () => any
232+
}
233+
219234
return {
220235
finishAssertions,
221236

222-
verifyUpcomingAssertions (subject, options = {}, callbacks = {}) {
237+
// TODO: define the specific type of options
238+
verifyUpcomingAssertions (subject, options: Record<string, any> = {}, callbacks: VerifyUpcomingAssertionsCallbacks = {}) {
223239
const cmds = getUpcomingAssertions()
224240

225241
cy.state('upcomingAssertions', cmds)
@@ -433,12 +449,13 @@ export const create = (Cypress, cy) => {
433449
cy.state('onBeforeLog', setCommandLog)
434450

435451
// send verify=true as the last arg
436-
return assertFn.apply(this, args.concat(true))
452+
return assertFn.apply(this, args.concat(true) as any)
437453
}
438454

439455
const fns = injectAssertionFns(cmds)
440456

441-
const subjects = []
457+
// TODO: remove any when the type of subject, the first argument of this function is specified.
458+
const subjects: any[] = []
442459

443460
// iterate through each subject
444461
// and force the assertion to return

0 commit comments

Comments
 (0)