@@ -8,6 +8,7 @@ const { onMock, removeListenerMock, themeState } = vi.hoisted(() => ({
88 themeState : {
99 shouldUseDarkColors : true ,
1010 themeSource : "system" ,
11+ setSourceError : null as unknown ,
1112 } ,
1213} ) ) ;
1314
@@ -17,6 +18,9 @@ vi.mock("electron", () => ({
1718 return themeState . shouldUseDarkColors ;
1819 } ,
1920 set themeSource ( value : string ) {
21+ if ( themeState . setSourceError !== null ) {
22+ throw themeState . setSourceError ;
23+ }
2024 themeState . themeSource = value ;
2125 } ,
2226 on : onMock ,
@@ -32,6 +36,7 @@ describe("ElectronTheme", () => {
3236 removeListenerMock . mockClear ( ) ;
3337 themeState . shouldUseDarkColors = true ;
3438 themeState . themeSource = "system" ;
39+ themeState . setSourceError = null ;
3540 } ) ;
3641
3742 it . effect ( "scopes native theme update listeners" , ( ) =>
@@ -49,4 +54,21 @@ describe("ElectronTheme", () => {
4954 assert . deepEqual ( removeListenerMock . mock . calls , [ [ "updated" , listener ] ] ) ;
5055 } ) . pipe ( Effect . provide ( ElectronTheme . layer ) ) ,
5156 ) ;
57+
58+ it . effect ( "preserves the requested source and cause when setting the theme fails" , ( ) =>
59+ Effect . gen ( function * ( ) {
60+ const cause = new Error ( "theme source failed" ) ;
61+ themeState . setSourceError = cause ;
62+ const electronTheme = yield * ElectronTheme . ElectronTheme ;
63+
64+ const error = yield * Effect . flip ( electronTheme . setSource ( "dark" ) ) ;
65+
66+ assert . instanceOf ( error , ElectronTheme . ElectronThemeSetSourceError ) ;
67+ assert . isTrue ( ElectronTheme . isElectronThemeSetSourceError ( error ) ) ;
68+ assert . strictEqual ( error . source , "dark" ) ;
69+ assert . strictEqual ( error . cause , cause ) ;
70+ assert . include ( error . message , "dark" ) ;
71+ assert . notInclude ( error . message , cause . message ) ;
72+ } ) . pipe ( Effect . provide ( ElectronTheme . layer ) ) ,
73+ ) ;
5274} ) ;
0 commit comments