本文整理汇总了TypeScript中@angular/http/testing.MockConnection类的典型用法代码示例。如果您正苦于以下问题:TypeScript MockConnection类的具体用法?TypeScript MockConnection怎么用?TypeScript MockConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockConnection类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('returns the data from the response', () => {
let connection: MockConnection;
mockBackend.connections.subscribe(c => connection = c);
let result;
service.get('42').subscribe((res) => { result = res; });
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: {
_id: '42',
endDate: '2016-11-30',
userRid: 'me'
}
})));
expect(result).toEqual(new Timesheet({
_id: '42',
endDate: '2016-11-30',
userRid: 'me'
}));
});
示例2: it
it('add a client release date', () => {
let connection: MockConnection;
mockBackend.connections.subscribe(c => connection = c);
let result: Version;
service.get().subscribe((res) => { result = res; });
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: [{ id: '2.0.4', name: 'Misty (2.0.4)', releaseDate: '2016-07-15' }]
})));
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: {
id: '1.2.0',
name: 'rusty nail',
date: '2017-05-10'
}
})));
expect(result.releaseDate).toEqual(moment('2017-05-10'));
});
示例3: expect
mockBackend.connections.subscribe((mockConnection:MockConnection)=>{
if(mockConnection.request.url == '/token'){
expect(mockConnection.request.method).toBe(RequestMethod.Post);
console.info(mockConnection.request.getBody());
expect(mockConnection.request.headers.get('Content-Type')).toEqual('x-www-form-urlencoded');
mockConnection.mockRespond( new Response(new ResponseOptions({body: login_response})));
}
});
示例4: it
it('gets the specified project', () => {
let connection: MockConnection;
mockBackend.connections.subscribe(c => connection = c);
let result;
service.get('42731138').subscribe((res) => { result = res; });
expect(connection.request.url).toEqual(`${environment.dataService}/projects/42731138`);
expect(connection.request.method).toEqual(RequestMethod.Get);
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: {
_id: '42731138',
name: 'Deep Geeky Thoughts About Total Control'
}
})));
expect(result).toEqual(new Project({
_id: '42731138',
name: 'Deep Geeky Thoughts About Total Control'
}));
});
示例5: ResponseOptions
(connection: MockConnection) => {
connection.mockRespond(new Response(
new ResponseOptions({
body: [
{
id: 2,
username: "username"
}]
}
)));
});
示例6: it
it('saves the token if the login is successful', () => {
let connection: MockConnection;
mockBackend.connections.subscribe(c => connection = c);
spyOn(authenticationTokenService, 'set');
service.login('user', 'password').subscribe((res) => {
expect(authenticationTokenService.set).toHaveBeenCalledTimes(1);
expect(authenticationTokenService.set).toHaveBeenCalledWith('IAmToken');
});
connection.mockRespond(new Response(new ResponseOptions({
status: 200,
body: {
success: true,
user: {
firstName: 'James',
lastName: 'Jones'
},
token: 'IAmToken'
}
})));
});
示例7: Response
backend.connections.subscribe((connection:MockConnection) => {
let mockResponseBody, response;
if (connection.request.url === `/${PATHS.authenticate}`) {
mockResponseBody = {
status: "success",
username: username,
sessionId: sessionId
};
response = new Response(new ResponseOptions({body: JSON.stringify(mockResponseBody)}));
connection.mockRespond(response);
} else {
mockResponseBody = {
status: "success"
};
response = new Response(new ResponseOptions({body: JSON.stringify(mockResponseBody)}));
connection.mockRespond(response);
}
});
示例8: getPointLog
public getPointLog(connection: MockConnection) {
const id = parseInt(connection.request.url.match(/\/api\/player\/([0-9]+)\/pointlog/i)[1], 10);
let response = new Response(new ResponseOptions({
body: JSON.stringify(this.pointLogDb.get(id))
}));
connection.mockRespond(response);
}
示例9: ResponseOptions
backend.connections.subscribe((connection: MockConnection) => {
const options = new ResponseOptions({
body: JSON.stringify(MockKnowledgeApi)
});
connection.mockRespond(new Response(options));
expect(connection.request.method).toEqual(RequestMethod.Get);
expect(connection.request.url).toBe(
`http://lookup.dbpedia.org/api/search/KeywordSearch` +
`?&QueryString=${searchquery}`
);
});
示例10: get
public get(connection: MockConnection) {
const id = parseInt(connection.request.url.match(/\/([0-9]+)/i)[1], 10);
const foundTournament = this.tournamentDb.get(id);
if (foundTournament) {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(foundTournament)
})));
} else {
connection.mockError(new ErrorResponse(new ResponseOptions({
body: 'Tournament not found',
status: 404
})));
}
}