forked from bahmutov/cypress-if
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
84 lines (77 loc) · 2.38 KB
/
index.d.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* A function that returns true if the value is good for "if" branch
* No Cypress commands allowed.
*/
type PredicateFn = (x: any) => boolean
/**
* A function that uses Chai assertions inside.
* No Cypress commands allowed.
*/
type AssertionFn = (x: any) => void
declare namespace Cypress {
interface Chainable {
/**
* Child `.if()` command to start an optional chain
* depending on the subject
* @param assertion Chai assertion (optional, existence by default)
* @param value Assertion value
* @example
* cy.get('#close').if('visible').click()
* cy.wrap(1).if('equal', 1).should('equal', 1)
*/
if(assertion?: string, value?: any): Chainable<any>
/**
* Child `.if()` command to start an optional chain
* depending on the subject
* @param callback Predicate function (returning a Boolean value)
* @example
* cy.wrap(1).if(n => n % 2 === 0)...
*/
if(callback: PredicateFn): Chainable<any>
/**
* Child `.if()` command to start an optional chain
* depending on the subject
* @param callback Function with Chai assertions
* @example
* cy.wrap(1).if(n => expect(n).to.equal(1))...
*/
if(callback: AssertionFn): Chainable<any>
/**
* Creates new chain of commands that only
* execute if the previous `.if()` command skipped
* the "IF" branch. Note: `.if()` passes its subject
* to the `.else()`
* You can also print a message if the ELSE branch
* is taken
* @param message Message to print to the console. Optional.
* @example
* cy.get('checkox#agree')
* .if('checked').log('Already agreed')
* .else().check()
* @example
* cy.get('...')
* .if('not.visible').log('Not visible')
* .else('visible')
*/
else(message?: any): Chainable<any>
/**
* Finishes if/else commands and continues
* with the subject yielded by the original command
* or if/else path taken
* @example
* cy.get('checkbox')
* .if('not.checked').check()
* .else().log('already checked')
* .finally().should('be.checked')
*/
finally(): Chainable<any>
/**
* A simple way to throw an error
* @example
* cy.get('li')
* .if('not.have.length', 3)
* .raise('wrong number of todo items')
*/
raise(x: string | Error): Chainable<void>
}
}