1- import { beforeEach , describe , expect , it , vi } from " vitest" ;
2- import { constructCoreClass } from " ./class" ;
1+ import { beforeEach , describe , expect , it , vi } from ' vitest'
2+ import { constructCoreClass } from ' ./class'
33
4- const lazyImportMock = vi . fn ( ( fn ) => fn ( ) ) ;
5- const renderMock = vi . fn ( ) ;
6- const portalMock = vi . fn ( ( props : any ) => < div > { props . children } </ div > ) ;
4+ const lazyImportMock = vi . fn ( ( fn ) => fn ( ) )
5+ const renderMock = vi . fn ( )
6+ const portalMock = vi . fn ( ( props : any ) => < div > { props . children } </ div > )
77
8- vi . mock ( " solid-js" , async ( ) => {
9- const actual = await vi . importActual < any > ( " solid-js" ) ;
8+ vi . mock ( ' solid-js' , async ( ) => {
9+ const actual = await vi . importActual < any > ( ' solid-js' )
1010 return {
1111 ...actual ,
1212 lazy : lazyImportMock ,
1313 }
14- } ) ;
14+ } )
1515
16- vi . mock ( " solid-js/web" , async ( ) => {
17- const actual = await vi . importActual < any > ( " solid-js/web" ) ;
16+ vi . mock ( ' solid-js/web' , async ( ) => {
17+ const actual = await vi . importActual < any > ( ' solid-js/web' )
1818 return {
1919 ...actual ,
2020 render : renderMock ,
2121 Portal : portalMock ,
22- } ;
23- } ) ;
24-
22+ }
23+ } )
2524
26- describe ( " constructCoreClass" , ( ) => {
25+ describe ( ' constructCoreClass' , ( ) => {
2726 beforeEach ( ( ) => {
28- vi . clearAllMocks ( ) ;
27+ vi . clearAllMocks ( )
28+ } )
29+ it ( 'should export DevtoolsCore and NoOpDevtoolsCore classes and make no calls to Solid.js primitives' , ( ) => {
30+ const [ DevtoolsCore , NoOpDevtoolsCore ] = constructCoreClass (
31+ '@test/devtools-mock-package' ,
32+ )
33+ expect ( DevtoolsCore ) . toBeDefined ( )
34+ expect ( NoOpDevtoolsCore ) . toBeDefined ( )
35+ expect ( lazyImportMock ) . not . toHaveBeenCalled ( )
2936 } )
30- it ( "should export DevtoolsCore and NoOpDevtoolsCore classes and make no calls to Solid.js primitives" , ( ) => {
31- const [ DevtoolsCore , NoOpDevtoolsCore ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
32- expect ( DevtoolsCore ) . toBeDefined ( ) ;
33- expect ( NoOpDevtoolsCore ) . toBeDefined ( ) ;
34- expect ( lazyImportMock ) . not . toHaveBeenCalled ( ) ;
35- } ) ;
36-
37- it ( "DevtoolsCore should call solid primitives when mount is called" , async ( ) => {
38- const [ DevtoolsCore , _ ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
39- const instance = new DevtoolsCore ( ) ;
40- await instance . mount ( document . createElement ( "div" ) , "dark" )
41- expect ( renderMock ) . toHaveBeenCalled ( ) ;
42- } ) ;
43-
44- it ( "DevtoolsCore should throw if mount is called twice without unmounting" , async ( ) => {
45- const [ DevtoolsCore , _ ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
46- const instance = new DevtoolsCore ( ) ;
47- await instance . mount ( document . createElement ( "div" ) , "dark" )
48- await expect ( instance . mount ( document . createElement ( "div" ) , "dark" ) ) . rejects . toThrow ( "Devtools is already mounted" ) ;
49- } ) ;
5037
51- it ( "DevtoolsCore should throw if unmount is called before mount" , ( ) => {
52- const [ DevtoolsCore , _ ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
53- const instance = new DevtoolsCore ( ) ;
54- expect ( ( ) => instance . unmount ( ) ) . toThrow ( "Devtools is not mounted" ) ;
55- } ) ;
38+ it ( 'DevtoolsCore should call solid primitives when mount is called' , async ( ) => {
39+ const [ DevtoolsCore , _ ] = constructCoreClass ( '@test/devtools-mock-package' )
40+ const instance = new DevtoolsCore ( )
41+ await instance . mount ( document . createElement ( 'div' ) , 'dark' )
42+ expect ( renderMock ) . toHaveBeenCalled ( )
43+ } )
5644
57- it ( "DevtoolsCore should allow mount after unmount" , async ( ) => {
58- const [ DevtoolsCore , _ ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
59- const instance = new DevtoolsCore ( ) ;
60- await instance . mount ( document . createElement ( "div" ) , "dark" )
61- instance . unmount ( ) ;
62- await expect ( instance . mount ( document . createElement ( "div" ) , "dark" ) ) . resolves . not . toThrow ( ) ;
63- } ) ;
45+ it ( 'DevtoolsCore should throw if mount is called twice without unmounting' , async ( ) => {
46+ const [ DevtoolsCore , _ ] = constructCoreClass ( '@test/devtools-mock-package' )
47+ const instance = new DevtoolsCore ( )
48+ await instance . mount ( document . createElement ( 'div' ) , 'dark' )
49+ await expect (
50+ instance . mount ( document . createElement ( 'div' ) , 'dark' ) ,
51+ ) . rejects . toThrow ( 'Devtools is already mounted' )
52+ } )
6453
54+ it ( 'DevtoolsCore should throw if unmount is called before mount' , ( ) => {
55+ const [ DevtoolsCore , _ ] = constructCoreClass ( '@test/devtools-mock-package' )
56+ const instance = new DevtoolsCore ( )
57+ expect ( ( ) => instance . unmount ( ) ) . toThrow ( 'Devtools is not mounted' )
58+ } )
6559
60+ it ( 'DevtoolsCore should allow mount after unmount' , async ( ) => {
61+ const [ DevtoolsCore , _ ] = constructCoreClass ( '@test/devtools-mock-package' )
62+ const instance = new DevtoolsCore ( )
63+ await instance . mount ( document . createElement ( 'div' ) , 'dark' )
64+ instance . unmount ( )
65+ await expect (
66+ instance . mount ( document . createElement ( 'div' ) , 'dark' ) ,
67+ ) . resolves . not . toThrow ( )
68+ } )
6669
67- it ( "NoOpDevtoolsCore should not call any solid primitives when mount is called" , async ( ) => {
68- const [ _ , NoOpDevtoolsCore ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
69- const noOpInstance = new NoOpDevtoolsCore ( ) ;
70- await noOpInstance . mount ( document . createElement ( "div" ) , "dark" )
70+ it ( 'NoOpDevtoolsCore should not call any solid primitives when mount is called' , async ( ) => {
71+ const [ _ , NoOpDevtoolsCore ] = constructCoreClass (
72+ '@test/devtools-mock-package' ,
73+ )
74+ const noOpInstance = new NoOpDevtoolsCore ( )
75+ await noOpInstance . mount ( document . createElement ( 'div' ) , 'dark' )
7176
72- expect ( lazyImportMock ) . not . toHaveBeenCalled ( ) ;
73- expect ( renderMock ) . not . toHaveBeenCalled ( ) ;
74- expect ( portalMock ) . not . toHaveBeenCalled ( ) ;
75- } ) ;
77+ expect ( lazyImportMock ) . not . toHaveBeenCalled ( )
78+ expect ( renderMock ) . not . toHaveBeenCalled ( )
79+ expect ( portalMock ) . not . toHaveBeenCalled ( )
80+ } )
7681
77- it ( "NoOpDevtoolsCore should not throw if mount is called multiple times" , async ( ) => {
78- const [ _ , NoOpDevtoolsCore ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
79- const noOpInstance = new NoOpDevtoolsCore ( ) ;
80- await noOpInstance . mount ( document . createElement ( "div" ) , "dark" )
81- await expect ( noOpInstance . mount ( document . createElement ( "div" ) , "dark" ) ) . resolves . not . toThrow ( ) ;
82- } ) ;
82+ it ( 'NoOpDevtoolsCore should not throw if mount is called multiple times' , async ( ) => {
83+ const [ _ , NoOpDevtoolsCore ] = constructCoreClass (
84+ '@test/devtools-mock-package' ,
85+ )
86+ const noOpInstance = new NoOpDevtoolsCore ( )
87+ await noOpInstance . mount ( document . createElement ( 'div' ) , 'dark' )
88+ await expect (
89+ noOpInstance . mount ( document . createElement ( 'div' ) , 'dark' ) ,
90+ ) . resolves . not . toThrow ( )
91+ } )
8392
84- it ( "NoOpDevtoolsCore should not throw if unmount is called before mount" , ( ) => {
85- const [ _ , NoOpDevtoolsCore ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
86- const noOpInstance = new NoOpDevtoolsCore ( ) ;
87- expect ( ( ) => noOpInstance . unmount ( ) ) . not . toThrow ( ) ;
88- } ) ;
93+ it ( 'NoOpDevtoolsCore should not throw if unmount is called before mount' , ( ) => {
94+ const [ _ , NoOpDevtoolsCore ] = constructCoreClass (
95+ '@test/devtools-mock-package' ,
96+ )
97+ const noOpInstance = new NoOpDevtoolsCore ( )
98+ expect ( ( ) => noOpInstance . unmount ( ) ) . not . toThrow ( )
99+ } )
89100
90- it ( "NoOpDevtoolsCore should not throw if unmount is called after mount" , async ( ) => {
91- const [ _ , NoOpDevtoolsCore ] = constructCoreClass ( "@test/devtools-mock-package" ) ;
92- const noOpInstance = new NoOpDevtoolsCore ( ) ;
93- await noOpInstance . mount ( document . createElement ( "div" ) , "dark" )
94- expect ( ( ) => noOpInstance . unmount ( ) ) . not . toThrow ( ) ;
95- } ) ;
96- } ) ;
101+ it ( 'NoOpDevtoolsCore should not throw if unmount is called after mount' , async ( ) => {
102+ const [ _ , NoOpDevtoolsCore ] = constructCoreClass (
103+ '@test/devtools-mock-package' ,
104+ )
105+ const noOpInstance = new NoOpDevtoolsCore ( )
106+ await noOpInstance . mount ( document . createElement ( 'div' ) , 'dark' )
107+ expect ( ( ) => noOpInstance . unmount ( ) ) . not . toThrow ( )
108+ } )
109+ } )
0 commit comments