@@ -12,8 +12,6 @@ import {
1212 mock ,
1313} from 'bun:test'
1414
15- import { createThemeStore } from '../theme-store'
16-
1715beforeAll ( ( ) => {
1816 document . documentElement . removeAttribute ( 'data-theme' )
1917} )
@@ -31,7 +29,10 @@ describe('themeStore', () => {
3129 document . documentElement . removeAttribute ( 'data-theme' )
3230 } )
3331
34- it ( 'should return themeStore object for browser' , ( ) => {
32+ it ( 'should return themeStore object for browser' , async ( ) => {
33+ const modulePath = require . resolve ( '../theme-store' )
34+ delete require . cache [ modulePath ]
35+ const { createThemeStore } = await import ( '../theme-store' )
3536 const themeStore = createThemeStore ( )
3637 expect ( themeStore ) . toBeDefined ( )
3738 expect ( themeStore . get ) . toEqual ( expect . any ( Function ) )
@@ -46,7 +47,10 @@ describe('themeStore', () => {
4647 expect ( themeStore . set ( 'dark' as any ) ) . toBeUndefined ( )
4748 } )
4849
49- it ( 'should call subscriber when theme changes via set' , ( ) => {
50+ it ( 'should call subscriber when theme changes via set' , async ( ) => {
51+ const modulePath = require . resolve ( '../theme-store' )
52+ delete require . cache [ modulePath ]
53+ const { createThemeStore } = await import ( '../theme-store' )
5054 const themeStore = createThemeStore ( )
5155 const callback = mock ( )
5256
@@ -61,7 +65,10 @@ describe('themeStore', () => {
6165 expect ( themeStore . get ( ) ) . toBe ( 'light' as any )
6266 } )
6367
64- it ( 'should unsubscribe correctly' , ( ) => {
68+ it ( 'should unsubscribe correctly' , async ( ) => {
69+ const modulePath = require . resolve ( '../theme-store' )
70+ delete require . cache [ modulePath ]
71+ const { createThemeStore } = await import ( '../theme-store' )
6572 const themeStore = createThemeStore ( )
6673 const callback = mock ( )
6774
@@ -77,9 +84,12 @@ describe('themeStore', () => {
7784 expect ( callback ) . toHaveBeenCalledTimes ( 1 )
7885 } )
7986
80- it ( 'should read initial theme from data-theme attribute' , ( ) => {
87+ it ( 'should read initial theme from data-theme attribute' , async ( ) => {
8188 document . documentElement . setAttribute ( 'data-theme' , 'dark' )
8289
90+ const modulePath = require . resolve ( '../theme-store' )
91+ delete require . cache [ modulePath ]
92+ const { createThemeStore } = await import ( '../theme-store' )
8393 const themeStore = createThemeStore ( )
8494 const callback = mock ( )
8595
@@ -90,6 +100,9 @@ describe('themeStore', () => {
90100 } )
91101
92102 it ( 'should update theme when data-theme attribute changes via MutationObserver' , async ( ) => {
103+ const modulePath = require . resolve ( '../theme-store' )
104+ delete require . cache [ modulePath ]
105+ const { createThemeStore } = await import ( '../theme-store' )
93106 const themeStore = createThemeStore ( )
94107 const callback = mock ( )
95108
@@ -106,7 +119,10 @@ describe('themeStore', () => {
106119 expect ( themeStore . get ( ) ) . toBe ( 'dark' as any )
107120 } )
108121
109- it ( 'should handle multiple subscribers' , ( ) => {
122+ it ( 'should handle multiple subscribers' , async ( ) => {
123+ const modulePath = require . resolve ( '../theme-store' )
124+ delete require . cache [ modulePath ]
125+ const { createThemeStore } = await import ( '../theme-store' )
110126 const themeStore = createThemeStore ( )
111127 const callback1 = mock ( )
112128 const callback2 = mock ( )
@@ -121,6 +137,9 @@ describe('themeStore', () => {
121137 } )
122138
123139 it ( 'should filter mutations by type and target' , async ( ) => {
140+ const modulePath = require . resolve ( '../theme-store' )
141+ delete require . cache [ modulePath ]
142+ const { createThemeStore } = await import ( '../theme-store' )
124143 const themeStore = createThemeStore ( )
125144 const callback = mock ( )
126145
0 commit comments