File tree 1 file changed +23
-3
lines changed
1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -248,9 +248,29 @@ the encoding in order to read the file as a
248
248
249
249
### ` this ` context
250
250
251
- If you store and access the fixture data using ` this ` test context object, make
252
- sure to use ` function () { ... } ` callbacks. Otherwise the test engine will NOT
253
- have ` this ` pointing at the test context.
251
+ To store and access the fixture data, prefer to use the global ` globalThis `
252
+ property over directly the ` this ` keyword.
253
+
254
+ ``` javascript
255
+ describe (' User page' , () => {
256
+ beforeEach (() => {
257
+ cy .fixture (' user' ).then ((user ) => {
258
+ // "globalThis" points at global this value
259
+ globalThis .user = user
260
+ })
261
+ })
262
+
263
+ // the test callback is in "() => { ... }" form
264
+ it (' has user' , () => {
265
+ // globalThis.user exists
266
+ expect (globalThis .user .firstName ).to .equal (' Jane' )
267
+ })
268
+ })
269
+ ```
270
+
271
+ If you store and access the fixture data using directly ` this ` keyword in test
272
+ context object, make sure to use ` function () { ... } ` callbacks. Otherwise
273
+ the test engine will NOT have ` this ` pointing at the test context.
254
274
255
275
``` javascript
256
276
describe (' User page' , () => {
You can’t perform that action at this time.
0 commit comments