Skip to content

Commit

Permalink
fixed-2750 (#2779)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurramkarthiknetha authored Dec 24, 2024
1 parent d25a795 commit dbe3387
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import fs from 'fs';
import { vi } from 'vitest';
import inquirer from 'inquirer';
import { askForTalawaApiUrl } from './askForTalawaApiUrl';

jest.mock('fs');
jest.mock('inquirer', () => ({
prompt: jest.fn(),
}));
vi.mock('fs');
vi.mock('inquirer', async () => {
const actual = await vi.importActual('inquirer');
return {
...actual,
prompt: vi.fn(),
};
});

describe('WebSocket URL Configuration', () => {
beforeEach(() => {
jest.resetAllMocks();
vi.clearAllMocks();
});

test('should convert http URL to ws WebSocket URL', async () => {
Expand All @@ -27,12 +32,12 @@ describe('WebSocket URL Configuration', () => {
});

test('should retain default WebSocket URL if no new endpoint is provided', async () => {
jest
.spyOn(inquirer, 'prompt')
.mockResolvedValueOnce({ endpoint: 'http://localhost:4000/graphql/' });
vi.spyOn(inquirer, 'prompt').mockResolvedValueOnce({
endpoint: 'http://localhost:4000/graphql/',
});
await askForTalawaApiUrl();

const writeFileSyncSpy = jest.spyOn(fs, 'writeFileSync');
const writeFileSyncSpy = vi.spyOn(fs, 'writeFileSync');
expect(writeFileSyncSpy).not.toHaveBeenCalled();
});
});

0 comments on commit dbe3387

Please sign in to comment.