@@ -3,7 +3,6 @@ import { unstable_createRoot } from "./createRoot.js";
33import { applyTheme } from "./themeAndMode.js" ;
44
55initializeI18n ( ) ;
6- const consoleError = jest . spyOn ( console , "error" ) ;
76jest . mock ( "./themeAndMode.js" ) ;
87window . scrollTo = jest . fn ( ) ;
98
@@ -200,6 +199,7 @@ describe("preview", () => {
200199 } ) ;
201200
202201 test ( "unknown bricks" , async ( ) => {
202+ const consoleError = jest . spyOn ( console , "error" ) ;
203203 consoleError . mockReturnValue ( ) ;
204204 const root = unstable_createRoot ( container , { unknownBricks : "silent" } ) ;
205205
@@ -230,6 +230,7 @@ describe("preview", () => {
230230 root . unmount ( ) ;
231231 expect ( container . innerHTML ) . toBe ( "" ) ;
232232 expect ( portal . innerHTML ) . toBe ( "" ) ;
233+ consoleError . mockRestore ( ) ;
233234 } ) ;
234235
235236 test ( "fail" , async ( ) => {
@@ -351,6 +352,8 @@ describe("preview", () => {
351352 } ) ;
352353
353354 test ( "templates in scope fragment" , async ( ) => {
355+ const consoleWarn = jest . spyOn ( console , "warn" ) ;
356+ consoleWarn . mockReturnValue ( ) ;
354357 const root = unstable_createRoot ( container ) ;
355358
356359 await root . render (
@@ -380,10 +383,43 @@ describe("preview", () => {
380383 expect ( tpl ?. tagName . toLowerCase ( ) ) . toBe ( "isolated-tpl-a" ) ;
381384 expect ( tpl ?. innerHTML ) . toBe ( "<p>Template A</p>" ) ;
382385
386+ expect ( consoleWarn ) . toHaveBeenCalledTimes ( 0 ) ;
387+
388+ // Redefine the same template.
389+ await root . render (
390+ [
391+ {
392+ brick : "isolated-tpl-a" ,
393+ } ,
394+ ] ,
395+ {
396+ templates : [
397+ {
398+ name : "isolated-tpl-a" ,
399+ bricks : [
400+ {
401+ brick : "p" ,
402+ properties : {
403+ textContent : "Template A Updated" ,
404+ } ,
405+ } ,
406+ ] ,
407+ } ,
408+ ] ,
409+ }
410+ ) ;
411+ expect ( container . firstElementChild ?. innerHTML ) . toBe (
412+ "<p>Template A Updated</p>"
413+ ) ;
414+ expect ( consoleWarn ) . toHaveBeenCalledTimes ( 1 ) ;
415+
383416 root . unmount ( ) ;
417+ consoleWarn . mockRestore ( ) ;
384418 } ) ;
385419
386420 test ( "using unknown templates in scope fragment" , async ( ) => {
421+ const consoleError = jest . spyOn ( console , "error" ) ;
422+ consoleError . mockReturnValue ( ) ;
387423 const root = unstable_createRoot ( container ) ;
388424
389425 await root . render ( [
@@ -397,5 +433,6 @@ describe("preview", () => {
397433 expect ( tpl ?. innerHTML ) . toBe ( "" ) ;
398434
399435 root . unmount ( ) ;
436+ consoleError . mockRestore ( ) ;
400437 } ) ;
401438} ) ;
0 commit comments