Skip to content

Commit

Permalink
refracting jest to vitest issue-PalisadoesFoundation#2749
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanrule committed Dec 31, 2024
1 parent 6349f3f commit 8e71d36
Showing 1 changed file with 16 additions and 9 deletions.
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 , expect , beforeEach , describe} from 'vitest';

vi.mock('inquirer', async (importOriginal) => {
const actual = await importOriginal<typeof import('inquirer')>();
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 @@ -48,3 +53,5 @@ describe('askForTalawaApiUrl', () => {
expect(result).toBe('http://localhost:4000/graphql/');
});
});


0 comments on commit 8e71d36

Please sign in to comment.