api.test.ts 957 B

12345678910111213141516171819202122232425262728293031323334
  1. import API, {instance} from 'packs/frontend/api';
  2. import MockAdapter from 'axios-mock-adapter';
  3. describe('API', (): void => {
  4. const mock = new MockAdapter(instance);
  5. afterAll(
  6. (): void => {
  7. mock.restore();
  8. }
  9. );
  10. describe('API.Pokemon', (): void => {
  11. describe('index()', (): void => {
  12. it('returns the response', async (): Promise<any> => {
  13. const expected = {foo: 'bar'};
  14. mock.onGet('/api/v1/pokemon').reply(200, expected);
  15. const response = await API.Pokemon.index();
  16. expect(response.data).toEqual(expected);
  17. });
  18. });
  19. describe('get(id)', (): void => {
  20. it('returns the response', async (): Promise<any> => {
  21. const expected = {id: 1, name: 'pukuchu'};
  22. mock.onGet(`/api/v1/pokemon/${expected.id}`).reply(200, expected);
  23. const response = await API.Pokemon.get(expected.id);
  24. expect(response.data).toEqual(expected);
  25. });
  26. });
  27. });
  28. });