11import ReactCustomBlocksApp from "@examples/06-custom-schema/react-custom-blocks/src/App" ;
22import VanillaCustomBlocksApp from "@examples/vanilla-js/react-vanilla-custom-blocks/src/App" ;
3- import { describe , test } from "vite-plus/test" ;
3+ import { afterAll , beforeAll , describe , expect , test } from "vite-plus/test" ;
44import { render } from "vitest-browser-react" ;
5- import { userEvent } from "../../utils/context.js" ;
5+ import { commands , userEvent } from "../../utils/context.js" ;
66import { EDITOR_SELECTOR } from "../../utils/const.js" ;
77import {
88 compareDocToSnapshot ,
@@ -12,6 +12,22 @@ import {
1212} from "../../utils/editor.js" ;
1313
1414describe ( "Check custom block functionality" , ( ) => {
15+ const imageCommands = commands as unknown as {
16+ mockCustomBlockImages ( action : "install" | "remove" ) : Promise < void > ;
17+ } ;
18+ beforeAll ( ( ) => imageCommands . mockCustomBlockImages ( "install" ) ) ;
19+ afterAll ( ( ) => imageCommands . mockCustomBlockImages ( "remove" ) ) ;
20+
21+ async function waitForImage ( ) {
22+ await expect
23+ . poll (
24+ ( ) =>
25+ document . querySelector < HTMLImageElement > ( "img.simple-image" )
26+ ?. naturalWidth ?? 0 ,
27+ )
28+ . toBeGreaterThan ( 0 ) ;
29+ }
30+
1531 test ( "Should be able to interactively update vanilla custom blocks" , async ( ) => {
1632 await render ( < VanillaCustomBlocksApp /> ) ;
1733 await waitForSelector ( EDITOR_SELECTOR ) ;
@@ -20,6 +36,7 @@ describe("Check custom block functionality", () => {
2036 await sleep ( 500 ) ;
2137
2238 await compareDocToSnapshot ( "vanillaInteractivity" ) ;
39+ await waitForImage ( ) ;
2340 await expectElement ( document . body ) . toMatchScreenshot (
2441 "vanilla-interactivity" ,
2542 ) ;
@@ -33,6 +50,7 @@ describe("Check custom block functionality", () => {
3350 await sleep ( 500 ) ;
3451
3552 await compareDocToSnapshot ( "reactInteractivity" ) ;
53+ await waitForImage ( ) ;
3654 await expectElement ( document . body ) . toMatchScreenshot ( "react-interactivity" ) ;
3755 } ) ;
3856} ) ;
0 commit comments