api.test.js 887 B

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