Skip to content

Commit

Permalink
Refactor : src/setup/checkConnection/checkConnection from Jest to Vit…
Browse files Browse the repository at this point in the history
…est #2751 (#2767)

* file name changed

* prettier check
  • Loading branch information
Ramneet04 authored Dec 24, 2024
1 parent 22b267a commit 7025360
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { checkConnection } from './checkConnection';
import { vi, describe, beforeEach, it, expect } from 'vitest';
vi.mock('node-fetch');

jest.mock('node-fetch');

global.fetch = jest.fn((url) => {
global.fetch = vi.fn((url) => {
if (url === 'http://example.com/graphql/') {
const responseInit: ResponseInit = {
status: 200,
Expand All @@ -22,11 +22,11 @@ global.fetch = jest.fn((url) => {

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

test('should return true and log success message if the connection is successful', async () => {
jest.spyOn(console, 'log').mockImplementation((string) => string);
vi.spyOn(console, 'log').mockImplementation((string) => string);
const result = await checkConnection('http://example.com/graphql/');

expect(result).toBe(true);
Expand All @@ -39,7 +39,7 @@ describe('checkConnection', () => {
});

it('should return false and log error message if the connection fails', async () => {
jest.spyOn(console, 'log').mockImplementation((string) => string);
vi.spyOn(console, 'log').mockImplementation((string) => string);
const result = await checkConnection(
'http://example_not_working.com/graphql/',
);
Expand Down

0 comments on commit 7025360

Please sign in to comment.