本文整理匯總了TypeScript中app/entities/todo/todo.service.TodoService類的典型用法代碼示例。如果您正苦於以下問題:TypeScript service.TodoService類的具體用法?TypeScript service.TodoService怎麽用?TypeScript service.TodoService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了service.TodoService類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('Todo Service', () => {
let injector: TestBed;
let service: TodoService;
let httpMock: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [TodoService]
});
injector = getTestBed();
service = injector.get(TodoService);
httpMock = injector.get(HttpTestingController);
});
describe('Service methods', () => {
it('should call correct URL', () => {
service.find(123).subscribe(() => {});
const req = httpMock.expectOne({ method: 'GET' });
const resourceUrl = SERVER_API_URL + 'api/todos';
expect(req.request.url).toEqual(resourceUrl + '/' + 123);
});
it('should create a Todo', () => {
service.create(new Todo(null)).subscribe(received => {
expect(received.body.id).toEqual(null);
});
const req = httpMock.expectOne({ method: 'POST' });
req.flush({ id: null });
});
it('should update a Todo', () => {
service.update(new Todo(123)).subscribe(received => {
expect(received.body.id).toEqual(123);
});
const req = httpMock.expectOne({ method: 'PUT' });
req.flush({ id: 123 });
});
it('should return a Todo', () => {
service.find(123).subscribe(received => {
expect(received.body.id).toEqual(123);
});
const req = httpMock.expectOne({ method: 'GET' });
req.flush({ id: 123 });
});
it('should return a list of Todo', () => {
service.query(null).subscribe(received => {
expect(received.body[0].id).toEqual(123);
});
const req = httpMock.expectOne({ method: 'GET' });
req.flush([new Todo(123)]);
});
it('should delete a Todo', () => {
service.delete(123).subscribe(received => {
expect(received.url).toContain('/' + 123);
});
const req = httpMock.expectOne({ method: 'DELETE' });
req.flush(null);
});
it('should propagate not found response', () => {
service.find(123).subscribe(null, (_error: any) => {
expect(_error.status).toEqual(404);
});
const req = httpMock.expectOne({ method: 'GET' });
req.flush('Invalid request parameters', {
status: 404,
statusText: 'Bad Request'
});
});
});
afterEach(() => {
httpMock.verify();
});
});
示例2: it
it('should delete a Todo', () => {
service.delete(123).subscribe(received => {
expect(received.url).toContain('/' + 123);
});
const req = httpMock.expectOne({ method: 'DELETE' });
req.flush(null);
});