@@ -1151,7 +1151,7 @@ describe('src/cy/commands/assertions', () => {
11511151 } )
11521152 } )
11531153
1154- context ( 'format quotation marks ', ( ) => {
1154+ describe ( 'message formatting ', ( ) => {
11551155 const expectMarkdown = ( test , message , done ) => {
11561156 cy . then ( ( ) => {
11571157 test ( )
@@ -1168,70 +1168,83 @@ describe('src/cy/commands/assertions', () => {
11681168 } )
11691169 }
11701170
1171- it ( 'preserves quotation marks in number strings' , ( done ) => {
1172- expectMarkdown ( ( ) => {
1173- try {
1174- expect ( 25 ) . to . eq ( '25' )
1175- } catch ( error ) { } /* eslint-disable-line no-empty */
1176- } ,
1177- `expected **25** to equal **'25'**` ,
1178- done )
1179- } )
1180-
1181- it ( 'preserves quotation marks in empty string' , ( done ) => {
1182- expectMarkdown ( ( ) => {
1183- try {
1184- expect ( 42 ) . to . eq ( '' )
1185- } catch ( error ) { } /* eslint-disable-line no-empty */
1186- } ,
1187- `expected **42** to equal **''**` ,
1188- done )
1189- } )
1171+ // https://github.com/cypress-io/cypress/issues/19116
1172+ it ( 'text with backslashes' , ( done ) => {
1173+ const text = '"<OE_D]dQ\\'
11901174
1191- it ( 'preserves quotation marks if escaped' , ( done ) => {
11921175 expectMarkdown (
1193- ( ) => expect ( `\'cypress\'` ) . to . eq ( `\'cypress\'` ) ,
1194- // ****'cypress'**** -> ** for emphasizing result string + ** for emphasizing the entire result.
1195- `expected **'cypress'** to equal ****'cypress'****` ,
1176+ ( ) => expect ( text ) . to . equal ( text ) ,
1177+ `expected **"<OE_D]dQ\\\\** to equal **"<OE_D]dQ\\\\**` ,
11961178 done ,
11971179 )
11981180 } )
11991181
1200- it ( 'removes quotation marks in DOM elements ', ( done ) => {
1201- expectMarkdown (
1202- ( ) => {
1203- cy . get ( 'body' ) . then ( ( $body ) => {
1204- expect ( $body ) . to . contain ( 'div ')
1205- } )
1182+ describe ( 'messages with quotation marks', ( ) => {
1183+ it ( 'preserves quotation marks in number strings' , ( done ) => {
1184+ expectMarkdown ( ( ) => {
1185+ try {
1186+ expect ( 25 ) . to . eq ( '25 ')
1187+ } catch ( error ) { } /* eslint-disable-line no-empty */
12061188 } ,
1207- `expected **<body>** to contain **div**` ,
1208- done ,
1209- )
1210- } )
1189+ `expected **25** to equal **'25'**` ,
1190+ done )
1191+ } )
12111192
1212- it ( 'removes quotation marks in strings' , ( done ) => {
1213- expectMarkdown ( ( ) => expect ( 'cypress' ) . to . eq ( 'cypress' ) , `expected **cypress** to equal **cypress**` , done )
1214- } )
1193+ it ( 'preserves quotation marks in empty string' , ( done ) => {
1194+ expectMarkdown ( ( ) => {
1195+ try {
1196+ expect ( 42 ) . to . eq ( '' )
1197+ } catch ( error ) { } /* eslint-disable-line no-empty */
1198+ } ,
1199+ `expected **42** to equal **''**` ,
1200+ done )
1201+ } )
12151202
1216- it ( 'removes quotation marks in objects' , ( done ) => {
1217- expectMarkdown (
1218- ( ) => expect ( { foo : 'bar' } ) . to . deep . eq ( { foo : 'bar' } ) ,
1219- `expected **{ foo: bar }** to deeply equal **{ foo: bar }**` ,
1220- done ,
1221- )
1222- } )
1203+ it ( 'preserves quotation marks if escaped' , ( done ) => {
1204+ expectMarkdown (
1205+ ( ) => expect ( `\'cypress\'` ) . to . eq ( `\'cypress\'` ) ,
1206+ // ****'cypress'**** -> ** for emphasizing result string + ** for emphasizing the entire result.
1207+ `expected **'cypress'** to equal ****'cypress'****` ,
1208+ done ,
1209+ )
1210+ } )
12231211
1224- it ( 'formats keys properly for "have.all.keys"' , ( done ) => {
1225- const person = {
1226- name : 'Joe' ,
1227- age : 20 ,
1228- }
1212+ it ( 'removes quotation marks in DOM elements' , ( done ) => {
1213+ expectMarkdown (
1214+ ( ) => {
1215+ cy . get ( 'body' ) . then ( ( $body ) => {
1216+ expect ( $body ) . to . contain ( 'div' )
1217+ } )
1218+ } ,
1219+ `expected **<body>** to contain **div**` ,
1220+ done ,
1221+ )
1222+ } )
12291223
1230- expectMarkdown (
1231- ( ) => expect ( person ) . to . have . all . keys ( 'name' , 'age' ) ,
1232- `expected **{ name: Joe, age: 20 }** to have keys **name**, and **age**` ,
1233- done ,
1234- )
1224+ it ( 'removes quotation marks in strings' , ( done ) => {
1225+ expectMarkdown ( ( ) => expect ( 'cypress' ) . to . eq ( 'cypress' ) , `expected **cypress** to equal **cypress**` , done )
1226+ } )
1227+
1228+ it ( 'removes quotation marks in objects' , ( done ) => {
1229+ expectMarkdown (
1230+ ( ) => expect ( { foo : 'bar' } ) . to . deep . eq ( { foo : 'bar' } ) ,
1231+ `expected **{ foo: bar }** to deeply equal **{ foo: bar }**` ,
1232+ done ,
1233+ )
1234+ } )
1235+
1236+ it ( 'formats keys properly for "have.all.keys"' , ( done ) => {
1237+ const person = {
1238+ name : 'Joe' ,
1239+ age : 20 ,
1240+ }
1241+
1242+ expectMarkdown (
1243+ ( ) => expect ( person ) . to . have . all . keys ( 'name' , 'age' ) ,
1244+ `expected **{ name: Joe, age: 20 }** to have keys **name**, and **age**` ,
1245+ done ,
1246+ )
1247+ } )
12351248 } )
12361249
12371250 describe ( 'formats strings with spaces' , ( done ) => {
@@ -1269,36 +1282,6 @@ describe('src/cy/commands/assertions', () => {
12691282 } )
12701283 } )
12711284
1272- // TODO: this suite should be merged with the suite above
1273- describe ( 'message formatting' , ( ) => {
1274- const expectMarkdown = ( test , message , done ) => {
1275- cy . then ( ( ) => {
1276- test ( )
1277- } )
1278-
1279- cy . on ( 'log:added' , ( attrs , log ) => {
1280- if ( attrs . name === 'assert' ) {
1281- cy . removeAllListeners ( 'log:added' )
1282-
1283- expect ( log . get ( 'message' ) ) . to . eq ( message )
1284-
1285- done ( )
1286- }
1287- } )
1288- }
1289-
1290- // https://github.com/cypress-io/cypress/issues/19116
1291- it ( 'text with backslashes' , ( done ) => {
1292- const text = '"<OE_D]dQ\\'
1293-
1294- expectMarkdown (
1295- ( ) => expect ( text ) . to . equal ( text ) ,
1296- `expected **"<OE_D]dQ\\\\** to equal **"<OE_D]dQ\\\\**` ,
1297- done ,
1298- )
1299- } )
1300- } )
1301-
13021285 context ( 'chai overrides' , ( ) => {
13031286 beforeEach ( function ( ) {
13041287 this . $body = cy . $$ ( 'body' )
0 commit comments