本文整理汇总了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'],
},
},
])
})
示例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,
},
},
])
})
示例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,
},
},
},
])
})
示例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')
})
示例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')
})
示例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);
});