本文整理汇总了TypeScript中@angular/http/testing.MockConnection.mockRespond方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MockConnection.mockRespond方法的具体用法?TypeScript MockConnection.mockRespond怎么用?TypeScript MockConnection.mockRespond使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/http/testing.MockConnection
的用法示例。
在下文中一共展示了MockConnection.mockRespond方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ResponseOptions
backend.connections.subscribe((connection: MockConnection) => {
let options = new ResponseOptions({
body: JSON.stringify(result)
});
connection.mockRespond(new Response(options));
});
示例2: ResponseOptions
mockBackend.connections.subscribe((c: MockConnection) => {
calledRequestMethod = c.request.method;
let options = new ResponseOptions({ status: 200, body: hero });
var response = new Response(options);
c.mockRespond(response);
});
示例3:
.subscribe((response: Response) => {
connection.mockRespond(response);
},
示例4: ResponseOptions
mock_backend.connections.subscribe((connection: MockConnection) => {
let options = new ResponseOptions({
body: json
});
connection.mockRespond(new Response(options));
});
开发者ID:MarcosPrieto,项目名称:Angular-AlbumStoreProductPage,代码行数:6,代码来源:product-service-getproducts-method-maps-response-to-json.projects.spec.ts
示例5: expect
mockBackend.connections.subscribe((mockConnection:MockConnection)=>{
expect(mockConnection.request.headers.get('userKey')).toBeDefined();
expect(mockConnection.request.headers.get('userKey')).toEqual(userKey);
expect(mockConnection.request.method).toBe(RequestMethod.Post);
mockConnection.mockRespond( new Response(new ResponseOptions({body: login_response})));
});
示例6:
backend.connections.subscribe((c: MockConnection) => {
c.mockRespond(baseResponse);
});
示例7: Response
(connection: MockConnection) => {
connection.mockRespond(new Response(
new ResponseOptions({ body: shopItemData })
));
}
示例8: expect
mockBackend.connections.subscribe((mockConnection:MockConnection)=>{
expect(mockConnection.request.method).toBe(RequestMethod.Get);
expect(mockConnection.request.url).toEqual(prepareUrl(baseUrl,url));
mockConnection.mockRespond( new Response(new ResponseOptions({body: mockResponse})));
});
示例9: Response
mockBackend.connections.subscribe((connection: MockConnection) => {
// POST create item request
if (connection.request.method === 1 && connection.request.url.search(/tenants/i) > -1) {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify({ data: JSON.parse(connection.request.getBody()) }),
status: 200,
statusText: "OK",
})));
return;
}
// POST update 'a1' (TenantOne) item request
if (connection.request.method === 1 && connection.request.url.search(/tenants\/a1/i) > -1) {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify({ data: TenantOne }),
status: 200,
statusText: "OK",
})));
return;
}
// GET form model request
if (connection.request.url.search(/tenants\/form-model/i) > -1) {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(FORM_MODEL),
status: 200,
statusText: "OK",
})));
return;
}
// GET form data request
if (connection.request.url.search(/tenants\/form-data/i) > -1) {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(FORM_DATA),
status: 200,
statusText: "OK",
})));
return;
}
// GET 'a1' (TenantOne) item data request
if (connection.request.url.search(/tenants\/a1/i) > -1) {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify({ data: TenantOne }),
status: 200,
statusText: "OK",
})));
return;
}
// GET 'b2' (TenantTwo) item data request
if (connection.request.url.search(/tenants\/b2/i) > -1) {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify({ data: TenantTwo }),
status: 200,
statusText: "OK",
})));
return;
}
});
示例10: expect
backend.connections.subscribe((connection: MockConnection) => {
expect(connection.request.method).toBe(RequestMethod.Get);
expect(connection.request.url).toBe('http://localhost:8080/application');
connection.mockRespond(new Response(new ResponseOptions({body: '{"expects": "JSON"}', status: 200})));
count++;
});