Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Sep 8, 2024
1 parent a53e30e commit 3631ca3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 9 additions & 6 deletions __tests__/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ jest.mock('axios');

const mockedAxios = axios as jest.Mocked<typeof axios>;

it('fetches successfully data from an API', async () => {
const data = { data: { userId: 1, id: 1, title: 'mock title' } };
mockedAxios.get.mockResolvedValue(data);
describe('api', () => {
it('fetches successfully data from an API', async () => {
const data = { data: { userId: 1, id: 1, title: 'mock title' } };
mockedAxios.get.mockResolvedValue(data);

const result = await fetchData('https://jsonplaceholder.typicode.com/todos/1');
expect(result).toEqual(data.data);
expect(mockedAxios.get).toHaveBeenCalledTimes(1);
const result = await fetchData('https://jsonplaceholder.typicode.com/todos/1');
expect(result).toEqual(data.data);
expect(mockedAxios.get).toHaveBeenCalledTimes(1);
});
});

6 changes: 4 additions & 2 deletions __tests__/sum.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { test, expect } from '@jest/globals';
import { sum } from '../src/sum';

test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
describe('sum', () => {
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
});

0 comments on commit 3631ca3

Please sign in to comment.