本文整理汇总了TypeScript中redux-mock-store.MockStoreEnhanced.dispatch方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MockStoreEnhanced.dispatch方法的具体用法?TypeScript MockStoreEnhanced.dispatch怎么用?TypeScript MockStoreEnhanced.dispatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redux-mock-store.MockStoreEnhanced
的用法示例。
在下文中一共展示了MockStoreEnhanced.dispatch方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('success', async () => {
await store.dispatch(User.sessionExpired())
expect(store.getActions()).toEqual([
{ type: UserActions.SessionExpired.type },
])
})
示例2: test
test('success', async () => {
const loc = {
pathname: 'a',
search: '?jobId=1&jobId=2&jobId=3',
hash: 'b',
selectedFeature: 'c',
}
const pushStateSpy = sinon.spy(history, 'pushState')
await store.dispatch(Route.navigateTo({ loc } as any))
const href = `${loc.pathname}${loc.search}${loc.hash}`
expect(pushStateSpy.callCount).toEqual(1)
expect(pushStateSpy.args[0]).toEqual([null, '', href])
expect(store.getActions()).toEqual([
{
type: RouteActions.Changed.type,
payload: {
pathname: loc.pathname,
search: loc.search,
hash: loc.hash,
selectedFeature: loc.selectedFeature,
href,
jobIds: ['1', '2', '3'],
},
},
])
pushStateSpy.restore()
})
示例3: it
it('should dispatch error on failure', async () => {
const error = new Error('The server is on fire');
mockAxios.request.mockRejectedValueOnce(error);
const p = store.dispatch(requestAction);
await expect(p).rejects.toEqual(error);
expect(mockAxios.request).toBeCalledTimes(1);
expect(store.getActions()).toMatchObject([
{
type: 'TEST_ACTION_REQUEST',
meta: {
requestStatus: REQUEST,
},
},
{
type: 'TEST_ACTION_FAILURE',
payload: error,
meta: {
requestStatus: FAILURE,
},
},
]);
});
示例4: test
test('success', async () => {
await store.dispatch(Tour.end())
expect(store.getActions()).toEqual([
{ type: TourActions.Ended.type },
])
})
示例5: test
test('success', async () => {
await store.dispatch(Map.clearBbox())
expect(store.getActions()).toEqual([
{ type: MapActions.BboxCleared.type },
])
})
示例6: 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'],
},
},
])
})