Skip to content

Commit

Permalink
pipeline fix
Browse files Browse the repository at this point in the history
  • Loading branch information
besdar committed Sep 22, 2024
1 parent 693a40c commit e898254
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/shared/config/mocks/jest-setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
import '@testing-library/react-native/extend-expect';

global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({}),
} as unknown as Response),
);
18 changes: 4 additions & 14 deletions src/shared/lib/__tests__/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/shared/ui/__tests__/ControlledPicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ControlledPicker', () => {
expect(input).toBeOnTheScreen();
});

it.skip('displays selected item label', async () => {
it('displays selected item label', async () => {
render(
<MockWrapperProvider>
<MockFormProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('ControlledSegmentedButtons', () => {
});
});

it.skip('selects an option when clicked', async () => {
it('selects an option when clicked', async () => {
render(
<MockWrapperProvider>
<MockFormProvider>
Expand Down

0 comments on commit e898254

Please sign in to comment.