当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript axios-mock-adapter.onGet函数代码示例

本文整理汇总了TypeScript中axios-mock-adapter.onGet函数的典型用法代码示例。如果您正苦于以下问题:TypeScript onGet函数的具体用法?TypeScript onGet怎么用?TypeScript onGet使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了onGet函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

    test('success', async () => {
      const mockResponse = {
        geoserver: 'a',
        'enabled-platforms': ['a', 'b'],
      }
      mockAdapter.onGet('/').reply(200, mockResponse)

      await store.dispatch(ApiStatus.fetch() as any)

      expect(clientSpies.get.callCount).toEqual(1)
      expect(clientSpies.get.args[0]).toEqual(['/'])

      expect(store.getActions()).toEqual([
        { type: ApiStatusActions.Fetching.type },
        {
          type: ApiStatusActions.FetchSuccess.type,
          payload: {
            geoserver: {
              wmsUrl: mockResponse.geoserver + '/wms',
            },
            enabledPlatforms: mockResponse['enabled-platforms'],
          },
        },
      ])
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:25,代码来源:apiStatusActions.test.ts

示例2: test

    test('success', async () => {
      const mockResponse = {
        jobs: {
          features: [1, 2, 3],
        },
      }
      const productLineId = '1'
      const sinceDate = '2'
      const url = getJobsEndpoint(productLineId, sinceDate)
      mockAdapter.onGet(url).reply(200, mockResponse)

      await store.dispatch(ProductLines.fetchJobs({ productLineId, sinceDate }) as any)

      expect(clientSpies.get.callCount).toEqual(1)
      expect(clientSpies.get.args[0]).toEqual([url])

      expect(store.getActions()).toEqual([
        { type: ProductLinesActions.FetchingJobs.type },
        {
          type: ProductLinesActions.FetchJobsSuccess.type,
          payload: {
            jobs: mockResponse.jobs.features,
          },
        },
      ])
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:26,代码来源:productLinesActions.test.ts

示例3: test

    test('success', async () => {
      store = mockStore({
        ...initialState,
        map: {
          bbox: [181, 0, 182, 1],
        },
      }) as any

      const state = store.getState()

      const mockResponse = {
        features: [
          { id: 'a' },
          { id: 'b' },
          { id: 'c' },
        ],
      }
      const searchUrl = getSearchUrl(state)
      mockAdapter.onGet(searchUrl).reply(200, mockResponse)

      await store.dispatch(Catalog.search() as any)

      expect(clientSpies.get.callCount).toEqual(1)
      expect(clientSpies.get.args[0]).toEqual([
        searchUrl,
        {
          params: {
            cloudCover: state.catalog.searchCriteria.cloudCover + .05,
            PL_API_KEY: state.catalog.apiKey,
            bbox: '-179,0,-178,1',
            acquiredDate: new Date(state.catalog.searchCriteria.dateFrom).toISOString(),
            maxAcquiredDate: new Date(state.catalog.searchCriteria.dateTo).toISOString(),
          },
        },
      ])

      const actions = store.getActions()
      expect(actions).toEqual([
        { type: CatalogActions.Searching.type },
        {
          type: CatalogActions.SearchSuccess.type,
          payload: {
            searchResults: {
              images: {
                features: mockResponse.features.map(f => {
                  return {
                    ...f,
                    id: state.catalog.searchCriteria.source + ':' + f.id,
                  }
                }),
              },
              count: mockResponse.features.length,
              startIndex: 0,
              totalCount: mockResponse.features.length,
            },
          },
        },
      ])
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:59,代码来源:catalogActions.test.ts

示例4: test

    test('request error', async () => {
      mockAdapter.onGet(ALGORITHM_ENDPOINT).reply(400)

      await store.dispatch(Algorithms.fetch() as any)

      const actions = store.getActions()
      expect(actions.length).toEqual(2)
      expect(actions[0]).toEqual({ type: AlgorithmsActions.Fetching.type })
      expect(actions[1].type).toEqual(AlgorithmsActions.FetchError.type)
      expect(actions[1].payload).toHaveProperty('error')
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:11,代码来源:algorithmsActions.test.ts

示例5: test

    test('invalid response data', async () => {
      const mockJob = { id: 'a' }
      mockAdapter.onGet(`${JOB_ENDPOINT}/${mockJob.id}`).reply(200)

      await store.dispatch(Jobs.fetchOne(mockJob.id) as any)

      const actions = store.getActions()
      expect(actions.length).toEqual(2)
      expect(actions[0]).toEqual({ type: JobsActions.FetchingOne.type })
      expect(actions[1].type).toEqual(JobsActions.FetchOneError.type)
      expect(actions[1].payload).toHaveProperty('error')
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:12,代码来源:jobsActions.test.ts

示例6: it

 it('should call all the default arg functions', async () => {
     const mock = new MockAdapter(axios, { delayResponse: 0 });
     const action = {
         types: ['one', 'two', 'three'],
         method: 'GET',
         requiresAuth: false,
         url: '/fake/url',
     };
     mock.onGet('/fake/url').reply(200, { data: 'some data' });
     await middleware.simpleApiCall({dispatch, getState})(next)(action);
     expect(dispatch.calledTwice).toBe(true);
 });
开发者ID:terranodo,项目名称:eventkit-cloud,代码行数:12,代码来源:middleware.spec.ts


注:本文中的axios-mock-adapter.onGet函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。