当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jest.marbles函数代码示例

本文整理汇总了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;未经允许,请勿转载。