Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refacted:src/setup/askForTalawaApiUrl/askForTalawaApiUrl.test.ts from Jest to Vitest #3095

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import inquirer from 'inquirer';
import { askForTalawaApiUrl } from './askForTalawaApiUrl';

jest.mock('inquirer', () => ({
prompt: jest.fn(),
}));
import { vi, it, describe, expect, beforeEach } from 'vitest';

vi.mock('inquirer', async (importOriginal) => {
const actual = await importOriginal<typeof inquirer>(); // Adding explicit type
return {
...actual,
prompt: vi.fn(),
};
});

describe('askForTalawaApiUrl', () => {
beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
});

test('should return the provided endpoint when user enters it', async () => {
const mockPrompt = jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({
it('should return the provided endpoint when user enters it', async () => {
const mockPrompt = vi.spyOn(inquirer, 'prompt').mockResolvedValueOnce({
endpoint: 'http://example.com/graphql/',
});

Expand All @@ -29,8 +34,8 @@ describe('askForTalawaApiUrl', () => {
expect(result).toBe('http://example.com/graphql/');
});

test('should return the default endpoint when the user does not enter anything', async () => {
const mockPrompt = jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({
it('should return the default endpoint when the user does not enter anything', async () => {
const mockPrompt = vi.spyOn(inquirer, 'prompt').mockResolvedValueOnce({
endpoint: 'http://localhost:4000/graphql/',
});

Expand All @@ -47,4 +52,4 @@ describe('askForTalawaApiUrl', () => {

expect(result).toBe('http://localhost:4000/graphql/');
});
});
});
Loading