Skip to content

Commit

Permalink
adding tests for utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Angamanga committed Jun 2, 2020
1 parent 58ffd2d commit 102bb34
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {getLanguages} from '../src/utils';
import axios from 'axios';
jest.mock('axios');

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

describe('getLanguages function', () => {
it('should return a list of languages', async () =>{
const languages = [{"code":"et-EE","name":"Estonian (Estonia)"},{"code":"fo","name":"Faroese"}];
const response = {"data":languages};
mockedAxios.get.mockImplementationOnce(() => Promise.resolve(response));
await expect(getLanguages('http://api.test.com')).resolves.toEqual(languages);
});
it('should return an error if something goes wrong', async () => {
const Error = 'network error';
mockedAxios.get.mockRejectedValue(Error);
const returnValue = await getLanguages('http://api.test.com');
expect(returnValue).toEqual(Error);
});
});

0 comments on commit 102bb34

Please sign in to comment.