@@ -4,7 +4,9 @@ test('自定义样式', async ({ page }) => {
44 page . on ( 'pageerror' , ( exception ) => expect ( exception ) . toBeNull ( ) )
55 await page . goto ( 'qr-code#style' )
66
7- const canvas = page . locator ( '.tiny-qr-code canvas' )
7+ const demo = page . locator ( '#style' )
8+ const wrapper = demo . locator ( '.tiny-qr-code' )
9+ const canvas = demo . locator ( '.tiny-qr-code canvas' )
810 await expect ( canvas ) . toBeVisible ( )
911
1012 const backgroundColor0 = await canvas . evaluate (
@@ -18,23 +20,7 @@ test('自定义样式', async ({ page }) => {
1820 )
1921
2022 expect ( backgroundColor0 === '#1677ff' ) . toBeTruthy ( )
21- await page . locator ( '.tiny-color-picker__inner' ) . click ( )
22- await page . locator ( '.black' ) . click ( )
23- await page . locator ( '.tiny-color-select-panel__inner__hue-select' ) . click ( )
24- await page . getByRole ( 'button' , { name : '选择' } ) . click ( )
25- const backgroundColor1 = await page . locator ( '.tiny-color-picker__inner' ) . evaluate ( ( el ) => {
26- return window . getComputedStyle ( el ) . backgroundColor
27- } )
2823
29- const backgroundColor2 = await canvas . evaluate (
30- ( el : any , { x, y } ) => {
31- const ctx = el . getContext ( '2d' )
32- const pixel = ctx . getImageData ( x , y , 1 , 1 ) . data
33-
34- return `rgb(${ pixel [ 0 ] } , ${ pixel [ 1 ] } , ${ pixel [ 2 ] } )`
35- } ,
36- { x : 1 , y : 1 }
37- )
38-
39- expect ( backgroundColor1 === backgroundColor2 ) . toBeTruthy ( )
24+ const box = await wrapper . boundingBox ( )
25+ expect ( box ?. width ) . toEqual ( 250 )
4026} )
0 commit comments