本文整理汇总了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$);
})
);
});
示例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$);
})
);
});
示例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);
});
});
示例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" }
}
]);
})
);
});