@@ -475,6 +475,7 @@ describe('network stubbing', { retries: 2 }, function () {
475
475
context ( 'network handling' , function ( ) {
476
476
// @see https://github.com/cypress-io/cypress/issues/8497
477
477
it ( 'can load transfer-encoding: chunked redirects' , function ( ) {
478
+ cy . intercept ( '*' )
478
479
const url4 = 'http://localhost:3501/fixtures/generic.html'
479
480
const url3 = `http://localhost:3501/redirect?href=${ encodeURIComponent ( url4 ) } `
480
481
const url2 = `https://localhost:3502/redirect?chunked=1&href=${ encodeURIComponent ( url3 ) } `
@@ -1209,10 +1210,10 @@ describe('network stubbing', { retries: 2 }, function () {
1209
1210
1210
1211
context ( 'correctly determines the content-length of an intercepted request' , function ( ) {
1211
1212
it ( 'when body is empty' , function ( done ) {
1212
- cy . route2 ( '/post-only' , function ( req ) {
1213
+ cy . intercept ( '/post-only' , function ( req ) {
1213
1214
req . body = ''
1214
1215
} ) . then ( function ( ) {
1215
- cy . route2 ( '/post-only' , function ( req ) {
1216
+ cy . intercept ( '/post-only' , function ( req ) {
1216
1217
expect ( req . headers [ 'content-length' ] ) . to . eq ( '0' )
1217
1218
1218
1219
done ( )
@@ -1224,10 +1225,10 @@ describe('network stubbing', { retries: 2 }, function () {
1224
1225
} )
1225
1226
1226
1227
it ( 'when body contains ascii' , function ( done ) {
1227
- cy . route2 ( '/post-only' , function ( req ) {
1228
+ cy . intercept ( '/post-only' , function ( req ) {
1228
1229
req . body = 'this is only ascii'
1229
1230
} ) . then ( function ( ) {
1230
- cy . route2 ( '/post-only' , function ( req ) {
1231
+ cy . intercept ( '/post-only' , function ( req ) {
1231
1232
expect ( req . headers [ 'content-length' ] ) . to . eq ( '18' )
1232
1233
1233
1234
done ( )
@@ -1239,10 +1240,10 @@ describe('network stubbing', { retries: 2 }, function () {
1239
1240
} )
1240
1241
1241
1242
it ( 'when body contains unicode' , function ( done ) {
1242
- cy . route2 ( '/post-only' , function ( req ) {
1243
+ cy . intercept ( '/post-only' , function ( req ) {
1243
1244
req . body = '🙃🤔'
1244
1245
} ) . then ( function ( ) {
1245
- cy . route2 ( '/post-only' , function ( req ) {
1246
+ cy . intercept ( '/post-only' , function ( req ) {
1246
1247
expect ( req . headers [ 'content-length' ] ) . to . eq ( '8' )
1247
1248
1248
1249
done ( )
@@ -1288,6 +1289,18 @@ describe('network stubbing', { retries: 2 }, function () {
1288
1289
. wait ( '@dest' )
1289
1290
} )
1290
1291
1292
+ it ( 'can simply wait on redirects without intercepting' , function ( ) {
1293
+ const href = `/fixtures/generic.html?t=${ Date . now ( ) } `
1294
+ const url = `/redirect?href=${ encodeURIComponent ( href ) } `
1295
+
1296
+ cy . intercept ( '/redirect' )
1297
+ . as ( 'redirect' )
1298
+ . intercept ( '/fixtures/generic.html' ) . as ( 'dest' )
1299
+ . then ( ( ) => fetch ( url ) )
1300
+ . wait ( '@redirect' )
1301
+ . wait ( '@dest' )
1302
+ } )
1303
+
1291
1304
// @see https://github.com/cypress-io/cypress/issues/7967
1292
1305
it ( 'can skip redirects via followRedirect' , function ( ) {
1293
1306
const href = `/fixtures/generic.html?t=${ Date . now ( ) } `
@@ -1983,6 +1996,36 @@ describe('network stubbing', { retries: 2 }, function () {
1983
1996
} )
1984
1997
} )
1985
1998
1999
+ // @see https://github.com/cypress-io/cypress/issues/8999
2000
+ it ( 'can spy on a 204 no body response' , function ( ) {
2001
+ cy . intercept ( '/status-code' ) . as ( 'status' )
2002
+ . then ( ( ) => {
2003
+ $ . get ( '/status-code?code=204' )
2004
+ } )
2005
+ . wait ( '@status' ) . its ( 'response.statusCode' ) . should ( 'eq' , 204 )
2006
+ } )
2007
+
2008
+ // @see https://github.com/cypress-io/cypress/issues/8934
2009
+ it ( 'can spy on a 304 not modified image response' , function ( ) {
2010
+ const url = `/fixtures/media/cypress.png?i=${ Date . now ( ) } `
2011
+
2012
+ cy . intercept ( url ) . as ( 'image' )
2013
+ . then ( ( ) => {
2014
+ $ . get ( { url, cache : true } )
2015
+ } )
2016
+ . then ( ( ) => {
2017
+ if ( Cypress . isBrowser ( 'firefox' ) ) {
2018
+ // strangely, Firefox requires some time to be waited before the first image response will be cached
2019
+ cy . wait ( 1000 )
2020
+ }
2021
+ } )
2022
+ . then ( ( ) => {
2023
+ $ . get ( { url, cache : true } )
2024
+ } )
2025
+ . wait ( '@image' ) . its ( 'response.statusCode' ) . should ( 'eq' , 200 )
2026
+ . wait ( '@image' ) . its ( 'response.statusCode' ) . should ( 'eq' , 304 )
2027
+ } )
2028
+
1986
2029
context ( 'with an intercepted request' , function ( ) {
1987
2030
it ( 'can dynamically alias the request' , function ( ) {
1988
2031
cy . intercept ( '/foo' , ( req ) => {
0 commit comments