3
3
4
4
describe ( 'cy.api' , ( ) => {
5
5
it ( 'calls API method' , ( ) => {
6
- cy . api (
7
- {
8
- url : '/'
9
- }
10
- )
6
+ cy . api ( {
7
+ url : '/' ,
8
+ } )
11
9
} )
12
10
13
- it ( 'calls API without displaying request' , { apiDisplayRequest : false } , ( ) => {
14
- cy . get ( 'body' ) . should ( 'not.contain' , 'MY PAGE' )
15
- cy . api (
16
- {
17
- url : '/' ,
18
- }
19
- )
20
- cy . get ( '.container' ) . should ( 'not.contain' , 'Request' )
21
- cy . visit ( '/test.html' )
22
- cy . contains ( 'MY PAGE' )
23
- cy . url ( ) . should ( 'contain' , 'test.html' )
24
- cy . api (
25
- {
11
+ it (
12
+ 'calls API without displaying request' ,
13
+ { apiDisplayRequest : false } ,
14
+ ( ) => {
15
+ cy . get ( 'body' ) . should ( 'not.contain' , 'MY PAGE' )
16
+ cy . api ( {
26
17
url : '/' ,
27
- } ,
28
- 'hello world'
29
- )
30
- cy . contains ( 'MY PAGE' )
31
- cy . get ( '.container' ) . should ( 'not.contain' , 'Request' )
32
- } )
18
+ } )
19
+ cy . get ( '.container' ) . should ( 'not.contain' , 'Request' )
20
+ cy . visit ( '/test.html' )
21
+ cy . contains ( 'MY PAGE' )
22
+ cy . url ( ) . should ( 'contain' , 'test.html' )
23
+ cy . api (
24
+ {
25
+ url : '/' ,
26
+ } ,
27
+ 'hello world' ,
28
+ )
29
+ cy . contains ( 'MY PAGE' )
30
+ cy . get ( '.container' ) . should ( 'not.contain' , 'Request' )
31
+ } ,
32
+ )
33
33
34
34
it ( 'calls several times' , ( ) => {
35
35
const options = { url : '/' }
@@ -41,17 +41,17 @@ describe('cy.api', () => {
41
41
it ( 'yields API call result' , ( ) => {
42
42
cy . api (
43
43
{
44
- url : '/'
44
+ url : '/' ,
45
45
} ,
46
- 'my hello world'
47
- ) . then ( response => {
46
+ 'my hello world' ,
47
+ ) . then ( ( response ) => {
48
48
expect ( response ) . to . include . keys ( [
49
49
'status' ,
50
50
'statusText' ,
51
51
'body' ,
52
52
'requestHeaders' ,
53
53
'headers' ,
54
- 'duration'
54
+ 'duration' ,
55
55
] )
56
56
expect ( response . body ) . to . equal ( 'Hello World!' )
57
57
} )
@@ -60,132 +60,96 @@ describe('cy.api', () => {
60
60
it ( 'yields result that has log messages' , ( ) => {
61
61
cy . api (
62
62
{
63
- url : '/'
63
+ url : '/' ,
64
64
} ,
65
- 'hello world'
65
+ 'hello world' ,
66
66
) . then ( ( { messages } ) => {
67
67
console . table ( messages )
68
68
// filter for "console.log" messages
69
69
const logs = Cypress . _ . filter ( messages , {
70
70
type : 'console' ,
71
- namespace : 'log'
71
+ namespace : 'log' ,
72
72
} )
73
73
expect ( logs , '1 console.log message' ) . to . have . length ( 1 )
74
74
expect ( logs [ 0 ] ) . to . deep . include ( {
75
75
type : 'console' ,
76
76
namespace : 'log' ,
77
- message : 'processing GET /'
77
+ message : 'processing GET /' ,
78
78
} )
79
79
} )
80
80
} )
81
81
82
-
83
- it ( 'yields result that has log messages with API_MESSAGES true' , {
84
- env : {
85
- API_MESSAGES : true
86
- }
87
- } , ( ) => {
88
- cy . api (
89
- {
90
- url : '/'
82
+ it (
83
+ 'yields result that has log messages with API_MESSAGES true' ,
84
+ {
85
+ env : {
86
+ API_MESSAGES : true ,
91
87
} ,
92
- 'hello world'
93
- ) . then ( ( { messages } ) => {
94
- console . table ( messages )
95
- // filter for "console.log" messages
96
- const logs = Cypress . _ . filter ( messages , {
97
- type : 'console' ,
98
- namespace : 'log'
88
+ } ,
89
+ ( ) => {
90
+ cy . api (
91
+ {
92
+ url : '/' ,
93
+ } ,
94
+ 'hello world' ,
95
+ ) . then ( ( { messages } ) => {
96
+ console . table ( messages )
97
+ // filter for "console.log" messages
98
+ const logs = Cypress . _ . filter ( messages , {
99
+ type : 'console' ,
100
+ namespace : 'log' ,
101
+ } )
102
+ expect ( logs , '1 console.log message' ) . to . have . length ( 1 )
103
+ expect ( logs [ 0 ] ) . to . deep . include ( {
104
+ type : 'console' ,
105
+ namespace : 'log' ,
106
+ message : 'processing GET /' ,
107
+ } )
99
108
} )
100
- expect ( logs , '1 console.log message' ) . to . have . length ( 1 )
101
- expect ( logs [ 0 ] ) . to . deep . include ( {
102
- type : 'console' ,
103
- namespace : 'log' ,
104
- message : 'processing GET /'
105
- } )
106
- } )
107
- } )
109
+ } ,
110
+ )
108
111
109
- it ( 'no log messages with API_MESSAGES false' , {
110
- env : {
111
- API_MESSAGES : false
112
- }
113
- } , ( ) => {
114
- cy . api (
115
- {
116
- url : '/'
112
+ it (
113
+ 'no log messages with API_MESSAGES false' ,
114
+ {
115
+ env : {
116
+ API_MESSAGES : false ,
117
117
} ,
118
- 'hello world'
119
- ) . then ( ( { messages } ) => {
120
- expect ( messages ) . to . have . length ( 0 )
121
- } )
122
- } )
118
+ } ,
119
+ ( ) => {
120
+ cy . api (
121
+ {
122
+ url : '/' ,
123
+ } ,
124
+ 'hello world' ,
125
+ ) . then ( ( { messages } ) => {
126
+ expect ( messages ) . to . have . length ( 0 )
127
+ } )
128
+ } ,
129
+ )
123
130
124
131
it ( 'mask credentials bearer' , ( ) => {
125
- cy . api (
126
- {
127
- url : '/' ,
128
- auth : {
129
- bearer : 'bearer'
130
- }
131
- }
132
- ) . then ( response => {
132
+ cy . api ( {
133
+ url : '/' ,
134
+ auth : {
135
+ bearer : 'bearer' ,
136
+ } ,
137
+ } ) . then ( ( response ) => {
133
138
expect ( response . status ) . eq ( 200 )
134
139
cy . contains ( '"bearer": "*****"' )
135
140
} )
136
141
} )
137
142
138
143
it ( 'mask credentials password' , ( ) => {
139
- cy . api (
140
- {
141
- url : '/' ,
142
- auth : {
143
- username : 'login' ,
144
- password : 'password'
145
- }
146
- }
147
- ) . then ( response => {
148
- expect ( response . status ) . eq ( 200 )
149
- cy . contains ( '"password": "*****"' )
150
- } )
151
- } )
152
-
153
- it ( 'mask credentials bearer and password' , ( ) => {
154
- cy . api (
155
- {
156
- url : '/' ,
157
- auth : {
158
- bearer : 'bearer' ,
159
- username : 'login' ,
160
- password : 'password'
161
- }
162
- }
163
- ) . then ( response => {
144
+ cy . api ( {
145
+ url : '/' ,
146
+ auth : {
147
+ username : 'login' ,
148
+ password : 'password' ,
149
+ } ,
150
+ } ) . then ( ( response ) => {
164
151
expect ( response . status ) . eq ( 200 )
165
- cy . contains ( '"bearer": "*****"' )
166
152
cy . contains ( '"password": "*****"' )
167
153
} )
168
154
} )
169
-
170
- it ( 'show credentials' , {
171
- env : {
172
- API_SHOW_CREDENTIALS : true
173
- }
174
- } , ( ) => {
175
- cy . api (
176
- {
177
- url : '/' ,
178
- auth : {
179
- bearer : 'bearer' ,
180
- username : 'login' ,
181
- password : 'password'
182
- }
183
- }
184
- ) . then ( response => {
185
- expect ( response . status ) . eq ( 200 )
186
- cy . contains ( '"bearer": "bearer"' )
187
- cy . contains ( '"password": "password"' )
188
- } )
189
- } )
190
-
191
155
} )
0 commit comments