@@ -27,41 +27,50 @@ span.second-to-last:nth-last-child(2) {
2727` ;
2828
2929test ( 'Nth-Child' , async ( { page } ) => {
30- await page . goto ( 'http://localhost:5173/' ) ;
31- const body = await page . evaluate ( async ( css ) => { document . body = await cssToHtml ( css ) ; return document . body . outerHTML ; } , css ) ;
30+ const conditions = async ( ) => {
31+ const body = await page . evaluate ( async css => { document . body = await cssToHtml ( css ) ; return document . body . outerHTML ; } , css ) ;
32+
33+ // The body should have exactly eight direct children.
34+ const bodyDirectChildren = page . locator ( 'body > *' ) ;
35+ expect ( await bodyDirectChildren . count ( ) ) . toBe ( 8 ) ;
3236
33- // The body should have exactly eight direct children.
34- const bodyDirectChildren = page . locator ( 'body > *' ) ;
35- expect ( await bodyDirectChildren . count ( ) ) . toBe ( 8 ) ;
37+ // The body's direct children should be in a specific order.
38+ const last = page . locator ( 'div.first:first-child + span + span + span + span.last + span + span.second-to-last + span:last-child' ) ;
39+ expect ( await last . count ( ) ) . toBe ( 1 ) ;
40+ const lastElement = await last . elementHandle ( ) ;
41+ expect ( lastElement ) . toBeTruthy ( ) ;
3642
37- // The body's direct children should be in a specific order.
38- const last = page . locator ( 'div.first:first-child + span + span + span + span.last + span + span.second-to-last + span:last-child' ) ;
39- expect ( await last . count ( ) ) . toBe ( 1 ) ;
40- const lastElement = await last . elementHandle ( ) ;
41- expect ( lastElement ) . toBeTruthy ( ) ;
43+ // The first element should have specific text content.
44+ const first = page . locator ( 'div.first:first-child' ) ;
45+ expect ( await first . count ( ) ) . toBe ( 1 ) ;
46+ const firstElement = await first . elementHandle ( ) ;
47+ const firstContent = await firstElement ?. innerHTML ( ) ;
48+ expect ( firstContent ) . toBe ( 'B' ) ;
4249
43- // The first element should have specific text content.
44- const first = page . locator ( 'div.first:first -child' ) ;
45- expect ( await first . count ( ) ) . toBe ( 1 ) ;
46- const firstElement = await first . elementHandle ( ) ;
47- const firstContent = await firstElement ?. innerHTML ( ) ;
48- expect ( firstContent ) . toBe ( 'B ' ) ;
50+ // The fifth element should have specific text content.
51+ const fifth = page . locator ( 'span.last:nth -child(5) ' ) ;
52+ expect ( await fifth . count ( ) ) . toBe ( 1 ) ;
53+ const fifthElement = await fifth . elementHandle ( ) ;
54+ const fifthContent = await fifthElement ?. innerHTML ( ) ;
55+ expect ( fifthContent ) . toBe ( 'C ' ) ;
4956
50- // The fifth element should have specific text content.
51- const fifth = page . locator ( 'span.last:nth-child(5 )' ) ;
52- expect ( await fifth . count ( ) ) . toBe ( 1 ) ;
53- const fifthElement = await fifth . elementHandle ( ) ;
54- const fifthContent = await fifthElement ?. innerHTML ( ) ;
55- expect ( fifthContent ) . toBe ( 'C ' ) ;
57+ // The seventh element should have specific text content.
58+ const seventh = page . locator ( 'span.second-to- last:nth-child(7 )' ) ;
59+ expect ( await seventh . count ( ) ) . toBe ( 1 ) ;
60+ const seventhElement = await seventh . elementHandle ( ) ;
61+ const seventhContent = await seventhElement ?. innerHTML ( ) ;
62+ expect ( seventhContent ) . toBe ( 'F ' ) ;
5663
57- // The seventh element should have specific text content.
58- const seventh = page . locator ( 'span.second-to-last:nth-child(7)' ) ;
59- expect ( await seventh . count ( ) ) . toBe ( 1 ) ;
60- const seventhElement = await seventh . elementHandle ( ) ;
61- const seventhContent = await seventhElement ?. innerHTML ( ) ;
62- expect ( seventhContent ) . toBe ( 'F' ) ;
64+ // The last element should have specific text content.
65+ const lastContent = await lastElement ?. innerHTML ( ) ;
66+ expect ( lastContent ) . toBe ( 'E' ) ;
67+ } ;
68+
69+ // Bundle.
70+ await page . goto ( 'http://localhost:5173/' ) ;
71+ await conditions ( ) ;
6372
64- // The last element should have specific text content .
65- const lastContent = await lastElement ?. innerHTML ( ) ;
66- expect ( lastContent ) . toBe ( 'E' ) ;
73+ // Static .
74+ await page . goto ( 'http://localhost:5173/static' ) ;
75+ await conditions ( ) ;
6776} ) ;
0 commit comments