當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript store.TodoService類代碼示例

本文整理匯總了TypeScript中app/services/store.TodoService的典型用法代碼示例。如果您正苦於以下問題:TypeScript TodoService類的具體用法?TypeScript TodoService怎麽用?TypeScript TodoService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TodoService類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: describe

describe('TodoStore', () => {
	let service: TodoService;
	let localStorage: MockLocalStorageService;

	beforeEach(() => {
		objects = [
			new Todo({ id: 1, title: 'one' }),
			new Todo({ id: 2, title: 'two' }),
			new Todo({ id: 3, title: 'three' })
		];
		localStorage = new MockLocalStorageService();
		service = new TodoService(localStorage as any);
	});

	it('should create a service', () => {
		expect(service).not.to.be.null;
	});

	it('should return an Observable of Todos', async () => {
		const result = await service.get().toPromise();
		expect(result).to.deep.equal(objects);
		expect(result).not.to.equal(objects);
	});

	it('should add a new Todo', async () => {
		const result = await service.add('four').toPromise();
		expect(result).to.have.lengthOf(4);
		expect(result[3].title).to.equal('four');
	});

	it('should update a Todo', async () => {
		const todo = objects[1];
		todo.title = 'two edited';
		const result = await service.update(todo).toPromise();
		expect(result).to.have.lengthOf(3);
		expect(result[1]).to.deep.equal(todo);
		expect(result[1]).not.to.equal(todo);
	});

	it('should set new Todos', async () => {
		const todos = [
			new Todo({ title: 'foo' }),
			new Todo({ title: 'bar' })
		];
		const result = await service.set(todos).toPromise();
		expect(result).to.have.lengthOf(2);
		expect(result).to.be.deep.equal(todos);
		expect(result).not.to.equal(todos);
	});

	it('should delete a Todo', async () => {
		const original = [...objects];
		const result = await service.delete(objects[1]).toPromise();
		expect(result).to.have.lengthOf(2);
		expect(result[0]).to.deep.equal(original[0]);
		expect(result[1]).to.deep.equal(original[2]);
	});
});
開發者ID:jason0x43,項目名稱:intern-examples,代碼行數:58,代碼來源:store.ts

示例2: async

	it('should delete a Todo', async () => {
		const original = [...objects];
		const result = await service.delete(objects[1]).toPromise();
		expect(result).to.have.lengthOf(2);
		expect(result[0]).to.deep.equal(original[0]);
		expect(result[1]).to.deep.equal(original[2]);
	});
開發者ID:jason0x43,項目名稱:intern-examples,代碼行數:7,代碼來源:store.ts

示例3: Todo

	it('should set new Todos', async () => {
		const todos = [
			new Todo({ title: 'foo' }),
			new Todo({ title: 'bar' })
		];
		const result = await service.set(todos).toPromise();
		expect(result).to.have.lengthOf(2);
		expect(result).to.be.deep.equal(todos);
		expect(result).not.to.equal(todos);
	});
開發者ID:jason0x43,項目名稱:intern-examples,代碼行數:10,代碼來源:store.ts


注:本文中的app/services/store.TodoService類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。