Skip to content

Commit 25e57eb

Browse files
committed
test: improve test coverage for configSlice
1 parent a8aba5d commit 25e57eb

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎packages/frontend/test/unit/store/configSlice.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,34 @@ describe('configSlice', () => {
8080
expect(store.getState().config.fontFamily).toEqual('TestFontAfterSave');
8181
expect(store.getState().config.fontSize).toEqual(18);
8282
});
83+
84+
it('should log and reject when saving config to backend fails', async () => {
85+
const error = new Error('network error');
86+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
87+
(global.fetch as jest.MockedFunction<typeof fetch>).mockRejectedValueOnce(error);
88+
89+
const action = await store.dispatch(
90+
saveConfigToBackend({
91+
fontFamily: 'SavedFont',
92+
fontFamilyMonospace: 'SavedMono',
93+
fontSize: 18,
94+
theme: 'default',
95+
syntaxHighlighterTheme: 'auto',
96+
enableBreaks: false,
97+
}),
98+
);
99+
100+
expect(action.type).toEqual('config/saveConfigToBackend/rejected');
101+
expect(action.error.message).toEqual('network error');
102+
expect(consoleErrorSpy).toHaveBeenCalledWith('Failed to save settings:', error);
103+
expect(api.fetchData).not.toHaveBeenCalled();
104+
expect(store.getState().config).toEqual({
105+
fontFamily: 'Roboto',
106+
fontFamilyMonospace: 'monospace',
107+
fontSize: 14,
108+
theme: 'default',
109+
syntaxHighlighterTheme: 'auto',
110+
enableBreaks: false,
111+
});
112+
});
83113
});

0 commit comments

Comments
 (0)