1- import { beforeEach , describe , expect , it , vi } from 'vitest'
1+ import { beforeEach , describe , expect , it } from 'vitest'
2+ import { page } from '@vitest/browser/context'
23
34import '../src/my-button.js'
45
@@ -7,27 +8,13 @@ describe('Button with increment', async () => {
78 document . body . innerHTML = '<my-button name="World"></my-button>'
89 } )
910
10- it ( 'should increment the count on each click' , ( ) => {
11- getInsideButton ( ) ?. click ( )
12- expect ( getInsideButton ( ) ?. textContent ) . toContain ( '1' )
13- } )
11+ it ( 'should increment the count on each click' , async ( ) => {
12+ await page . getByRole ( 'button' ) . click ( )
1413
15- it ( 'should show name props' , ( ) => {
16- getInsideButton ( )
17- expect ( document . body . querySelector ( 'my-button' ) ?. shadowRoot ?. innerHTML ) . toContain ( 'World' )
14+ await expect . element ( page . getByRole ( 'button' ) ) . toHaveTextContent ( '2' )
1815 } )
1916
20- it ( 'should dispatch count event on button click' , ( ) => {
21- const spyClick = vi . fn ( )
22-
23- document . querySelector ( 'my-button' ) ! . addEventListener ( 'count' , spyClick )
24-
25- getInsideButton ( ) ?. click ( )
26-
27- expect ( spyClick ) . toHaveBeenCalled ( )
17+ it ( 'should show name props' , async ( ) => {
18+ await expect . element ( page . getByRole ( 'heading' ) ) . toHaveTextContent ( 'World' )
2819 } )
2920} )
30-
31- function getInsideButton ( ) : HTMLElement | null | undefined {
32- return document . body . querySelector ( 'my-button' ) ?. shadowRoot ?. querySelector ( 'button' )
33- }
0 commit comments