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

TypeScript jest.marbles函数代码示例

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

本文整理汇总了TypeScript中rxjs-marbles/jest.marbles函数的典型用法代码示例。如果您正苦于以下问题:TypeScript marbles函数的具体用法?TypeScript marbles怎么用?TypeScript marbles使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了marbles函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

  describe("#fetchPlans", () => {
    it("makes a request", () => {
      mockRequest.mockReturnValueOnce(from([{}]));
      ServicePlansClient.fetchPlans("fakeService");
      expect(mockRequest).toHaveBeenCalled();
    });

    it("makes a request to the correct URL", () => {
      mockRequest.mockReturnValueOnce(from([{}]));
      ServicePlansClient.fetchPlans("fakeService");
      expect(mockRequest).toHaveBeenCalledWith("/service/fakeService/v1/plans");
    });

    it(
      "emits an event when the data is received",
      marbles(m => {
        const expectedResult = ["plan01", "plan02", "plan03"];
        const expected$ = m.cold("--(j|)", {
          j: {
            response: expectedResult,
            code: 200,
            message: "OK"
          }
        });

        mockRequest.mockReturnValueOnce(expected$);

        const result$ = ServicePlansClient.fetchPlans("test").pipe(take(1));
        m.expect(result$).toBeObservable(expected$);
      })
    );

    it(
      "emits an error if non-2XX API response",
      marbles(m => {
        const mockResult$ = m.cold("--j", {
          j: {
            code: 500,
            message: "Internal Server Error",
            response: []
          }
        });

        mockRequest.mockReturnValueOnce(mockResult$);

        const result$ = ServicePlansClient.fetchPlans("fakeService");

        const expected$ = m.cold("--#", undefined, {
          message:
            "Service Plans API request failed: 500 Internal Server Error:[]",
          name: "Error"
        });

        m.expect(result$).toBeObservable(expected$);
      })
    );
  });
开发者ID:dcos,项目名称:dcos-ui,代码行数:57,代码来源:ServicePlansClient-test.ts


示例2: describe

  describe("#fetchJobs", () => {
    it("makes a request", () => {
      mockRequest.mockReturnValueOnce(of({}));
      fetchJobs();
      expect(mockRequest).toHaveBeenCalled();
    });

    it("sends data to the correct URL", () => {
      mockRequest.mockReturnValueOnce(of({}));
      fetchJobs();
      expect(mockRequest).toHaveBeenCalledWith(
        `${
          Config.metronomeAPI
        }/v1/jobs?embed=activeRuns&embed=schedules&embed=historySummary`
      );
    });

    it(
      "emits an event if the data is received",
      marbles(m => {
        const expectedResult = [jobData, jobData] as JobResponse[];
        const expected$ = m.cold("--j|", {
          j: {
            response: expectedResult,
            code: 200,
            message: "ok"
          }
        });

        mockRequest.mockReturnValueOnce(expected$);
        const result$ = fetchJobs();
        m.expect(result$).toBeObservable(expected$);
      })
    );
  });
开发者ID:dcos,项目名称:dcos-ui,代码行数:35,代码来源:MetronomeClient-test.ts


示例3: describe

  describe("#queryCosmosForUIVersions", () => {
    it(
      "returns package result from query",
      marbles(m => {
        const queryResp$ = m.cold("--j|", {
          j: {
            data: {
              package: {
                name: "dcos-ui",
                versions: [
                  {
                    version: "2.0.0",
                    revision: "1"
                  }
                ]
              }
            }
          }
        });
        mockDataLayer.mockReturnValueOnce(queryResp$);

        const query$ = queryCosmosForUIVersions();
        const result$ = query$.pipe(take(1));
        m.expect(result$).toBeObservable(
          m.cold("--(j|)", {
            j: {
              name: "dcos-ui",
              versions: [
                {
                  version: "2.0.0",
                  revision: "1"
                }
              ]
            }
          })
        );
      })
    );

    it("makes a single query to data-layer", () => {
      mockDataLayer.mockReturnValueOnce(of({}));

      queryCosmosForUIVersions();
      expect(mockDataLayer).toHaveBeenCalledTimes(1);
    });
  });
开发者ID:dcos,项目名称:dcos-ui,代码行数:46,代码来源:queries-test.ts


示例4: describe

  describe("#rollbackUI", () => {
    it(
      "emits two actions",
      marbles(m => {
        mockDataLayer.mockReturnValueOnce(
          m.cold("-j|", {
            j: {
              data: {
                resetDCOSUI: "OK"
              }
            }
          })
        );
        const actionSpy = jest.spyOn(getAction$(), "next");

        rollbackUI(1);
        m.flush();
        expect(actionSpy).toHaveBeenCalledTimes(2);
      })
    );
    it(
      "emits Reset started action",
      marbles(m => {
        mockDataLayer.mockReturnValueOnce(
          m.cold("-j|", {
            j: {
              data: {
                resetDCOSUI: "OK"
              }
            }
          })
        );
        const actionSpy = jest.spyOn(getAction$(), "next");

        rollbackUI(1);
        expect(actionSpy.mock.calls[0]).toEqual([
          {
            type: "UIReset",
            action: "start",
            value: { message: "" }
          }
        ]);
      })
    );
    it(
      "emits Reset completed action",
      marbles(m => {
        mockDataLayer.mockReturnValueOnce(
          m.cold("-j|", {
            j: {
              data: {
                resetDCOSUI: "OK"
              }
            }
          })
        );
        const actionSpy = jest.spyOn(getAction$(), "next");

        rollbackUI(1);
        m.flush();
        expect(actionSpy.mock.calls[1]).toEqual([
          {
            type: "UIReset",
            action: "complete",
            value: { message: "OK" }
          }
        ]);
      })
    );
    it(
      "emits error if mutation fails",
      marbles(m => {
        mockDataLayer.mockReturnValueOnce(
          m.cold("-#", undefined, {
            message: "On No Something bad happened",
            name: "Error"
          })
        );
        const actionSpy = jest.spyOn(getAction$(), "next");

        rollbackUI(1);
        m.flush();
        expect(actionSpy.mock.calls[1]).toEqual([
          {
            type: "UIReset",
            action: "error",
            value: { message: "On No Something bad happened" }
          }
        ]);
      })
    );
  });
开发者ID:dcos,项目名称:dcos-ui,代码行数:92,代码来源:commands-test.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript rxjs.queueScheduler类代码示例发布时间:2022-05-25
下一篇:
TypeScript rxjs.Subscription类代码示例发布时间: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