Skip to content

Commit 733f057

Browse files
🧪 Add test for error path in loadSession
Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
1 parent 2be3698 commit 733f057

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎tests/api.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ describe('api.ts session management', () => {
6767
await expect(loadSession()).rejects.toThrow(SyntaxError);
6868
});
6969

70+
71+
test('loadSession throws when reading credential file fails', async () => {
72+
existsSyncSpy = spyOn(fs, 'existsSync').mockReturnValue(true);
73+
readFileSyncSpy = spyOn(fs, 'readFileSync').mockImplementation(() => {
74+
throw new Error('Read error');
75+
});
76+
77+
await expect(loadSession()).rejects.toThrow('Read error');
78+
expect(console.error).toHaveBeenCalledWith(
79+
expect.stringContaining('Failed to parse file')
80+
);
81+
});
7082
test('replaceSession sets session', () => {
7183
replaceSession({ token: 'new-token' });
7284
expect(getSession()?.token).toBe('new-token');

0 commit comments

Comments
 (0)