本文整理汇总了TypeScript中redux-mock-store.MockStoreEnhanced类的典型用法代码示例。如果您正苦于以下问题:TypeScript MockStoreEnhanced类的具体用法?TypeScript MockStoreEnhanced怎么用?TypeScript MockStoreEnhanced使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockStoreEnhanced类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe(requestMiddleware, () => {
const mockStore = configureStore([requestMiddleware]);
const requestAction = {
type: 'TEST_ACTION',
payload: {
method: 'GET',
url: 'http://example.com',
},
meta: {
[API_REQUEST]: 'TEST_ACTION',
},
};
let store: MockStoreEnhanced;
beforeEach(() => {
store = mockStore();
mockAxios.request.mockClear();
});
it('should make async calls and dispatch actions on success', async () => {
mockAxios.request.mockResolvedValueOnce({
status: 200,
statusText: 'OK',
data: {
hello: 'world',
},
headers: {
'content-type': 'application/json',
},
config: {},
});
await store.dispatch(requestAction);
expect(mockAxios.request).toBeCalledTimes(1);
expect(store.getActions()).toMatchObject([
{
type: 'TEST_ACTION_REQUEST',
meta: {
requestStatus: REQUEST,
},
},
{
type: 'TEST_ACTION_SUCCESS',
payload: {
hello: 'world',
},
meta: {
responseHeaders: {
'content-type': 'application/json',
},
requestStatus: SUCCESS,
},
},
]);
});
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,
},
},
]);
});
});
示例2: test
test('success', async () => {
const mockResponseData = {
jobs: {
features: ['a', 'b', 'c'],
},
}
mockAdapter.onGet(JOB_ENDPOINT).reply(200, mockResponseData)
await store.dispatch(Jobs.fetch() as any)
expect(clientSpies.get.callCount).toEqual(1)
expect(clientSpies.get.args[0]).toEqual([JOB_ENDPOINT])
expect(store.getActions()).toEqual([
{ type: JobsActions.Fetching.type },
{
type: JobsActions.FetchSuccess.type,
payload: {
records: mockResponseData.jobs.features,
},
},
])
})
示例3: test
test('success (with selected feature)', async () => {
const mockSelectedFeature = { id: 'c' }
const mockProductLines = [
{ id: 'a' },
{ id: 'b' },
]
store = mockStore({
...initialState,
route: {
...routeInitialState,
pathname: '/product-lines',
},
productLines: {
...productLinesInitialState,
records: mockProductLines,
},
map: {
...mapInitialState,
frames: [],
selectedFeature: mockSelectedFeature,
},
}) as any
await store.dispatch(Map.updateFrames() as any)
expect(store.getActions()).toEqual([
{
type: MapActions.FramesUpdated.type,
payload: {
frames: [
mockSelectedFeature,
...mockProductLines,
],
},
},
])
})
示例4: test
test('invalid saved data', async () => {
sessionStorage.setItem('searchCriteria', 'badJson')
sessionStorage.setItem('searchResults', 'badJson')
await store.dispatch(Catalog.deserialize())
expect(sessionStorage.getItem).toHaveBeenCalledTimes(2)
expect(sessionStorage.getItem).toHaveBeenCalledWith('searchCriteria')
expect(sessionStorage.getItem).toHaveBeenCalledWith('searchResults')
expect(localStorage.getItem).toHaveBeenCalledTimes(1)
expect(localStorage.getItem).toHaveBeenCalledWith('catalog_apiKey')
expect(store.getActions()).toEqual([
{
type: CatalogActions.Deserialized.type,
payload: {
apiKey: catalogInitialState.apiKey,
searchCriteria: catalogInitialState.searchCriteria,
searchResults: catalogInitialState.searchResults,
},
},
])
})
示例5: test
test('success', async () => {
const mockSteps = [
{
step: 1,
after: sinon.spy(),
},
{
step: 2,
before: sinon.spy(),
},
]
store = mockStore({
...initialState,
tour: {
...tourInitialState,
steps: mockSteps,
},
}) as any
await store.dispatch(Tour.goToStep(2) as any)
expect(mockSteps[0].after!.callCount).toEqual(1)
expect(mockSteps[1].before!.callCount).toEqual(1)
expect(scrollIntoViewStub.callCount).toEqual(1)
expect(store.getActions()).toEqual([
{ type: TourActions.StepChanging.type },
{
type: TourActions.StepChangeSuccess.type,
payload: {
step: 2,
},
},
])
})