How to use axios-mock-adapter - 10 common examples

To help you get started, we’ve selected a few axios-mock-adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gitlabhq / gitlabhq / spec / frontend / related_merge_requests / components / related_merge_requests_spec.js View on Github external
beforeEach((done) => {
    loadFixtures(FIXTURE_PATH);
    mockData = getJSONFixture(FIXTURE_PATH);

    // put the fixture in DOM as the component expects
    document.body.innerHTML = `<div id="js-issuable-app"></div>`;
    document.getElementById('js-issuable-app').dataset.initial = JSON.stringify(mockData);

    mock = new MockAdapter(axios);
    mock.onGet(`${API_ENDPOINT}?per_page=100`).reply(200, mockData, { 'x-total': 2 });

    wrapper = mount(localVue.extend(RelatedMergeRequests), {
      localVue,
      store: createStore(),
      propsData: {
        endpoint: API_ENDPOINT,
        projectNamespace: 'gitlab-org',
        projectPath: 'gitlab-ce',
      },
    });

    setImmediate(done);
  });
github gitlabhq / gitlabhq / spec / frontend / notes / old_notes_spec.js View on Github external
beforeEach(() => {
    loadFixtures(fixture);

    // Re-declare this here so that test_setup.js#beforeEach() doesn't
    // overwrite it.
    mockAxios = new MockAdapter(axios);

    $.ajax = () => {
      throw new Error('$.ajax should not be called through!');
    };

    // These jQuery+DOM tests are super flaky so increase the timeout to avoid
    // random failures.
    // It seems that running tests in parallel increases failure rate.
    jest.setTimeout(4000);
    setTestTimeoutOnce(4000);
  });
github ArkEcosystem / desktop-wallet / __tests__ / unit / store / modules / peer.spec.js View on Github external
import axios from 'axios'
import AxiosMockAdapter from 'axios-mock-adapter'
import Vue from 'vue'
import Vuex from 'vuex'
import apiClient, { client } from '@/plugins/api-client'
import store from '@/store'
import peers, { goodPeer1, goodPeer2, goodPeer4, goodPeer5, badPeer1 } from '../../__fixtures__/store/peer'
import { network1 } from '../../__fixtures__/store/network'
import { profile1 } from '../../__fixtures__/store/profile'

Vue.use(Vuex)
Vue.use(apiClient)

const axiosMock = new AxiosMockAdapter(axios)
const nethash = '2a44f340d76ffc3df204c5f38cd355b7496c9065a1ade2ef92071436bd72e867'

beforeAll(() => {
  network1.nethash = nethash
  store.commit('network/SET_ALL', [network1])
  store.commit('profile/CREATE', profile1)
  store.commit('session/SET_PROFILE_ID', profile1.id)
  store.dispatch('peer/set', peers)
})

beforeEach(() => {
  axiosMock.reset()
  client.version = 1
})

describe('peer store module', () => {
github modularcode / modular-material-admin-react-pro / src / _api / _mocks / index.ts View on Github external
const init = (instance: AxiosInstance) => {
  const mockAdapter = new MockAdapter(instance, { delayResponse: 200 })

  usersMocks.init(mockAdapter)
  organizationsMocks.init(mockAdapter)

  return mockAdapter
}
github gitlabhq / gitlabhq / spec / frontend / cycle_analytics / store / actions_spec.js View on Github external
beforeEach(() => {
        state = { requestPath: mockRequestPath };
        mock = new MockAdapter(axios);
        mock.onGet(mockRequestPath).reply(httpStatusCodes.BAD_REQUEST);
      });
github vuesion / vuesion / src / app / shared / modules / auth / actions.spec.ts View on Github external
beforeEach(() =&gt; {
    testContext = {
      dispatch: jest.fn() as Dispatch,
      commit: jest.fn() as Commit,
      state: AuthDefaultState(),
    } as ActionContext;

    mockAxios = new MockAdapter(HttpService);
  });
github gitlabhq / gitlabhq / spec / javascripts / environments / folder / environments_folder_view_spec.js View on Github external
beforeEach(() => {
    mock = new MockAdapter(axios);

    Component = Vue.extend(environmentsFolderViewComponent);
  });
github gitlabhq / gitlabhq / spec / frontend / feature_flags / components / edit_feature_flag_spec.js View on Github external
beforeEach((done) => {
    mock = new MockAdapter(axios);
    mock.onGet(`${TEST_HOST}/feature_flags.json`).replyOnce(200, {
      id: 21,
      iid: 5,
      active: true,
      created_at: '2019-01-17T17:27:39.778Z',
      updated_at: '2019-01-17T17:27:39.778Z',
      name: 'feature_flag',
      description: '',
      version: LEGACY_FLAG,
      edit_path: '/h5bp/html5-boilerplate/-/feature_flags/21/edit',
      destroy_path: '/h5bp/html5-boilerplate/-/feature_flags/21',
      scopes: [
        {
          id: 21,
          active: false,
          environment_scope: '*',
github gitlabhq / gitlabhq / spec / javascripts / pipelines / stage_spec.js View on Github external
beforeEach(() => {
    mock = new MockAdapter(axios);

    StageComponent = Vue.extend(stage);

    component = mountComponent(StageComponent, {
      stage: {
        status: {
          group: 'success',
          icon: 'status_success',
          title: 'success',
        },
        dropdown_path: 'path.json',
      },
      updateDropdown: false,
    });
  });

axios-mock-adapter

Axios adapter that allows to easily mock requests

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis

Popular axios-mock-adapter functions