Skip to content

Commit

Permalink
refacted:src/setup/askForTalawaApiUrl/askForTalawaApiUrl.test.ts from…
Browse files Browse the repository at this point in the history
… Jest to Vitest (#3095)

* refracting jest to vitest issue-#2749

* Fix formatting using Prettier

* fix

* fix

* fixed
  • Loading branch information
aryanrule authored Dec 31, 2024
1 parent 7ca3ae3 commit 56c1fbe
Showing 1 changed file with 14 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, describe, expect, beforeEach } from 'vitest';

vi.mock('inquirer', async () => {
const actual = await vi.importActual('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 Down

0 comments on commit 56c1fbe

Please sign in to comment.