test: Increase test coverage (#39)

* test: Increase test coverage

* Assert console.error on failed client.login test

* Remove redundant removeMember test
This commit is contained in:
critters.zip
2026-04-10 05:38:14 +10:00
committed by GitHub
parent 96c2abc06a
commit badc6baaf0
2 changed files with 64 additions and 1 deletions

View File

@@ -293,8 +293,23 @@ describe('bot', () => {
expect(client.login).toHaveBeenCalledWith(process.env.FLUXER_BOT_TOKEN)
})
test('login exits with code 1 if client.login fails', async () => {
// Arrange
let message = "client.login failed";
client.login = jest.fn().mockImplementation(() => { throw new Error(message) });
jest.spyOn(global.console, 'error').mockImplementation(() => {});
jest.spyOn(process, 'exit').mockImplementation(() => {});
// Act
await login();
// Assert
expect(console.error).toHaveBeenCalledTimes(1);
expect(console.error).toHaveBeenCalledWith('Login failed:', new Error(message));
expect(process.exit).toHaveBeenCalledTimes(1);
expect(process.exit).toHaveBeenCalledWith(1);
})
afterEach(() => {
// restore the spy created with spyOn
jest.restoreAllMocks();
});
})
})