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