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

TypeScript redux-mock-store.MockStoreEnhanced类代码示例

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

本文整理汇总了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,
        },
      },
    ]);
  });
});
开发者ID:nusmodifications,项目名称:nusmods,代码行数:85,代码来源:requests-middleware.test.ts


示例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,
          },
        },
      ])
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:23,代码来源:jobsActions.test.ts


示例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,
              ],
            },
          },
        ])
      })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:37,代码来源:mapActions.test.ts


示例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,
          },
        },
      ])
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:24,代码来源:catalogActions.test.ts


示例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,
          },
        },
      ])
    })
开发者ID:venicegeo,项目名称:bf-ui,代码行数:36,代码来源:tourActions.test.ts



注:本文中的redux-mock-store.MockStoreEnhanced类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript redux-observable.combineEpics函数代码示例发布时间:2022-05-25
下一篇:
TypeScript redux-mock-store.MockStore类代码示例发布时间: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