diff --git a/src/shared/config/mocks/jest-setup.ts b/src/shared/config/mocks/jest-setup.ts index 1d3ff30..e09f438 100644 --- a/src/shared/config/mocks/jest-setup.ts +++ b/src/shared/config/mocks/jest-setup.ts @@ -1 +1,7 @@ import '@testing-library/react-native/extend-expect'; + +global.fetch = jest.fn(() => + Promise.resolve({ + json: () => Promise.resolve({}), + } as unknown as Response), +); diff --git a/src/shared/lib/__tests__/update.test.ts b/src/shared/lib/__tests__/update.test.ts index 7a3226d..463b85a 100644 --- a/src/shared/lib/__tests__/update.test.ts +++ b/src/shared/lib/__tests__/update.test.ts @@ -2,42 +2,32 @@ import packageJSON from '../../../../package.json'; import {getRemoteAppVersion} from '../update'; describe('getRemoteAppVersion', () => { - let fetchSpy = jest.spyOn(global, 'fetch'); - - beforeEach(() => { - fetchSpy = jest.spyOn(global, 'fetch'); - }); - - afterAll(() => { - fetchSpy.mockRestore(); - }); - it('should return the version from the remote package.json', async () => { const mockVersion = '1.0.0'; const mockResponse = { version: mockVersion, }; - fetchSpy.mockResolvedValueOnce({ + (fetch as jest.Mock).mockResolvedValueOnce({ json: jest.fn().mockResolvedValueOnce(mockResponse), } as unknown as Response); const version = await getRemoteAppVersion(); - expect(fetchSpy).toHaveBeenCalledWith( + expect(global.fetch).toHaveBeenCalledWith( `https://raw.githubusercontent.com/${packageJSON.repository}/main/package.json`, ); expect(version).toBe(mockVersion); }); it('should throw an error if the fetch fails', async () => { - fetchSpy.mockRejectedValueOnce(new Error('Network error')); + (fetch as jest.Mock).mockRejectedValueOnce(new Error('Network error')); await expect(getRemoteAppVersion()).rejects.toThrow('Network error'); }); it('should throw an error if the response is not valid JSON', async () => { - fetchSpy.mockResolvedValueOnce({ + (fetch as jest.Mock).mockResolvedValueOnce({ json: jest.fn().mockRejectedValueOnce(new Error('Invalid JSON')), } as unknown as Response); diff --git a/src/shared/ui/__tests__/ControlledPicker.test.tsx b/src/shared/ui/__tests__/ControlledPicker.test.tsx index 3f06849..031d081 100644 --- a/src/shared/ui/__tests__/ControlledPicker.test.tsx +++ b/src/shared/ui/__tests__/ControlledPicker.test.tsx @@ -30,7 +30,7 @@ describe('ControlledPicker', () => { expect(input).toBeOnTheScreen(); }); - it.skip('displays selected item label', async () => { + it('displays selected item label', async () => { render( diff --git a/src/shared/ui/__tests__/ControlledSegmentedButtons.test.tsx b/src/shared/ui/__tests__/ControlledSegmentedButtons.test.tsx index 1cf761f..81fe5d5 100644 --- a/src/shared/ui/__tests__/ControlledSegmentedButtons.test.tsx +++ b/src/shared/ui/__tests__/ControlledSegmentedButtons.test.tsx @@ -39,7 +39,7 @@ describe('ControlledSegmentedButtons', () => { }); }); - it.skip('selects an option when clicked', async () => { + it('selects an option when clicked', async () => { render(