• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript axios-mock-adapter.onPost函数代码示例发布时间:2022-05-25
下一篇:
TypeScript axios.CancelToken类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap