Skip to content

Commit 192a37b

Browse files
🧪 Add test for error path in loadSession (#41)
* 🧪 Add test for error path in loadSession Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> * Fix linting errors Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
1 parent 7165924 commit 192a37b

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎tests/api.test.ts‎

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

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

0 commit comments

Comments
 (0)