本文整理匯總了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,
},
},
])
})