You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+50-108
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ import 'cypress-wait-frames'
21
21
22
22
<br />
23
23
24
-
If using TypeScript, install the latest version of [csstype](https://www.npmjs.com/package/csstype) for CSS properties autocompletion:
24
+
If using TypeScript, optionally install the latest version of [csstype](https://www.npmjs.com/package/csstype) for CSS properties autocompletion:
25
25
26
26
```bash
27
27
pnpm add -D csstype
@@ -45,9 +45,9 @@ Documentation on [retry-ability](https://docs.cypress.io/guides/core-concepts/re
45
45
46
46
<br />
47
47
48
-
## When to use it
48
+
## When I find it useful
49
49
50
-
There are cases where it's impossible to retain retry-ability and you might find yourself guessing timings using `cy.wait`.
50
+
There are cases where it's very hard to retain retry-ability and you might find yourself guessing timings using `cy.wait` or increasing the retry-ability timeout.
51
51
52
52
For example when asserting properties not available within Cypress queries:
53
53
@@ -63,120 +63,67 @@ cy.get('h1')
63
63
})
64
64
```
65
65
66
-
Or when futher assertions must rely on 100% accurate values:
67
-
68
-
```js
69
-
cy.get('#TriggerComplexTransition').click()
70
-
71
-
// Need to add cy.wait(t) to make sure desktopHeight is accurate
But scenarios can be disparate and more complex. Bottom line is that if you find yourself using `cy.wait()` as last resort, this package might be for you.
66
+
But scenarios can be disparate and more complex. Bottom line is that if you find yourself using `cy.wait()` as last resort to obtain values or wait for DOM/CSS properties to be idle, this package might be for you.
84
67
85
68
<br />
86
69
87
70
## Usage
88
71
89
-
Instead of guessing timings using `cy.wait` you can use `cy.waitFrames` to wait for a one or more properties to be idle after a specified number of frames.
90
-
91
-
Specify a `subject` to watch, one or more `property` and a number of `frames`. Command will resolve once queried properties haven't changed for that number of frames.
72
+
### Window
92
73
93
74
```js
94
-
cy.get('h1').eq(15).scrollIntoView()
95
-
96
75
cy.waitFrames({
97
-
subject: () =>cy.get('h1').eq(15),
98
-
property:'getBoundingClientRect.top',
99
-
frames:20// Wait for the property to be idle for 20 frames
100
-
}).then(([{ value }]) => {
101
-
cy.wrap(value).should('be.approximately', 0, 2) // Passes in any environment
102
-
})
103
-
```
104
-
105
-
You can also use it to just to wait for a property to be idle:
106
-
107
-
```js
108
-
Cypress.Commands.add('waitForResize', () => {
109
-
cy.waitFrames({
110
-
subject:cy.window,
111
-
property:'outerWidth',
112
-
frames:20
113
-
})
76
+
subject:cy.window,
77
+
property:'outerWidth'
114
78
})
115
-
```
116
-
117
-
```js
118
-
cy.waitForResize()
119
79
120
-
cy.log('Resized!') //This is executed once outerWidth isn't changed for 20 frames.
80
+
cy.log('Resized!') //Executed once 'outerWidth' isn't changed for 20 frames (default).
|`subject`| undefined | () => Chainable\<T> | Chainable to watch for properties. |:white_check_mark:|
128
-
|`property`| undefined | string \| string[]| One or more properties to watch. |:white_check_mark:|
129
-
|`frames`| 20 | number | Number of frames to wait. |:x:|
130
-
|`timeout`| 30 \* 1000 | number | Timeout in milliseconds. |:x:|
131
-
132
-
<br />
133
-
134
-
## Yields
135
-
136
-
A [Cypress Promise](https://docs.cypress.io/api/utilities/promise) which resolves to an array of objects (one for each property) or throws an error if `timeout` is reached:
|`property`| undefined |`string \| string[]`| One or more properties to watch. |:white_check_mark:|
112
+
|`frames`| 20 |`number`| Number of frames to wait. |:x:|
113
+
|`timeout`| 30 \* 1000 |`number`| Timeout in milliseconds before the command should fail. |:x:|
170
114
171
-
```js
172
-
cy.waitFrames({
173
-
subject: () =>cy.get('a').eq(0) // or () => cy.get('.my-selector')
174
-
})
175
-
```
115
+
<br />
116
+
117
+
## Yields
176
118
177
-
:bulb: Use `() => cy.get` to watch for DOM/CSS properties on any other HTMLElement.
119
+
A [Cypress Promise](https://docs.cypress.io/api/utilities/promise) which resolves to an array of objects (one for each property) or throws an error if `timeout` is reached:
178
120
179
-
:warning: When using `cy.get`, make sure to pass a function which returns the chainable.
|`subject`|`AUTWindow`\|`HTMLElement`| Subject yielded from `subject` option chainer. |
124
+
|`value`|`Primitive`| Property value at which the function resolved. |
125
+
|`property`|`string`| Awaited property name. |
126
+
|`time`|`DOMHighResTimestamp`| Time in ms that took to resolve since invoking. |
180
127
181
128
<br />
182
129
@@ -186,25 +133,25 @@ cy.waitFrames({
186
133
187
134
```js
188
135
cy.waitFrames({
189
-
subject:cy.window,
190
-
property:'scrollY',
191
-
frames:10
136
+
subject: () =>cy.get('html'),
137
+
property:'clientWidth'
192
138
})
193
139
```
194
140
195
141
### CSS properties
196
142
197
143
```js
198
144
cy.waitFrames({
199
-
subject: () =>cy.get('.my-element'),
200
-
property:'background-color', // or '--my-var'
201
-
frames:10
145
+
subject: () =>cy.get('#my-element'),
146
+
property:'background-color'
202
147
})
203
148
```
204
149
205
-
:bulb: Use _kebab-case_ for CSS properties. `getComputedStyle` is used internally to get the values.
150
+
:bulb: Use _kebab-case_ for CSS properties. [getComputedStyle](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) is used internally to get the values.
151
+
152
+
### Nested properties / methods
206
153
207
-
### Objects / methods properties
154
+
You can watch for methods or objects **maximum 1 nested property** which returns a primitive.
208
155
209
156
```js
210
157
cy.waitFrames({
@@ -215,29 +162,24 @@ cy.waitFrames({
215
162
216
163
```js
217
164
cy.waitFrames({
218
-
subject: () =>cy.get('.my-element'),
165
+
subject: () =>cy.get('a').eq(0),
219
166
property:'getBoundingClientRect.top'
220
167
})
221
168
```
222
169
223
-
:warning:Bear in mind that only methods or objects with **maximum 1 property** which returns a primitive are supported.
170
+
:warning:Methods with arity greater than 0 are not supported, (e.g. `getAttribute('href')`).
224
171
225
-
Methods with arity greater than 0 are not supported, _e.g. `getAttribute('href')`_.
172
+
### Mixed properties / methods
226
173
227
-
### Multiple properties / methods
228
-
229
-
You can watch for multiple properties as well:
174
+
You can watch for multiple properties as well, `waitFrames` will resolve once all properties are idle:
0 commit comments