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