当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Observable.of方法代码示例

本文整理汇总了TypeScript中rxjs/Rx.Observable.of方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Observable.of方法的具体用法?TypeScript Observable.of怎么用?TypeScript Observable.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rxjs/Rx.Observable的用法示例。


在下文中一共展示了Observable.of方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('should pass a blog item to remove to the blogService during delete', () => {
    blogRoll.ngOnInit();
    // alerts/confirm are an awful idea (short timeframe for this demo)
    // but we can deal with the confirm message box by mocking it away,
    // and returning true to continue processing - thanks Jasmine!
    spyOn(window, 'confirm')
       .and.callFake(() => { return true; });

    // now mock the actual call to
    spyOn(blogService, 'deleteBlogEntry')
       .and.returnValue(Observable.of({ complete: true}));
    let entry = new BlogEntry(null ,null, null, 15);
    blogRoll.deleteBlogEntry(entry);

    // collaborator behavior check
    expect(window.confirm).toHaveBeenCalled();
    expect(blogService.deleteBlogEntry).toHaveBeenCalledWith(15);
  });
开发者ID:7Silvan,项目名称:angular2-unittest-samples-rc,代码行数:18,代码来源:blog-roll-unit.spec.ts

示例2: beforeEach

    beforeEach(() => {

        fixture = TestBed.createComponent(ProcessCommentsComponent);
        component = fixture.componentInstance;
        service = fixture.debugElement.injector.get(TaskListService);

        getCommentsSpy = spyOn(service, 'getComments').and.returnValue(Observable.of([
            { message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} },
            { message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} },
            { message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }
        ]));

        componentHandler = jasmine.createSpyObj('componentHandler', [
            'upgradeAllRegistered',
            'upgradeElement'
        ]);
        window['componentHandler'] = componentHandler;
    });
开发者ID:gravitonian,项目名称:alfresco-ng2-components,代码行数:18,代码来源:process-comments.component.spec.ts

示例3: fakeAsync

                fakeAsync((service: Register, mockTranslate: MockLanguageService) => {
                    spyOn(service, 'save').and.returnValue(Observable.of({}));
                    comp.registerAccount.password = comp.confirmPassword = 'password';

                    comp.register();
                    tick();

                    expect(service.save).toHaveBeenCalledWith({
                        password: 'password',
                        langKey: 'fr'
                    });
                    expect(comp.success).toEqual(true);
                    expect(comp.registerAccount.langKey).toEqual('fr');
                    expect(mockTranslate.getCurrentSpy).toHaveBeenCalled();
                    expect(comp.errorUserExists).toBeNull();
                    expect(comp.errorEmailExists).toBeNull();
                    expect(comp.error).toBeNull();
                })
开发者ID:ATS01Dev,项目名称:HotMan,代码行数:18,代码来源:register.component.spec.ts

示例4: fakeAsync

                fakeAsync((service: Register) => {
                    spyOn(service, 'save').and.returnValue(Observable.of({}));
                    comp.registerAccount.password = comp.confirmPassword = 'password';

                    comp.register();
                    tick();

                    expect(service.save).toHaveBeenCalledWith({
                        password: 'password',
                        langKey: 'en'
                    });
                    expect(comp.success).toEqual(true);
                    expect(comp.registerAccount.langKey).toEqual('en');
                    
                    expect(comp.errorUserExists).toBeNull();
                    expect(comp.errorEmailExists).toBeNull();
                    expect(comp.error).toBeNull();
                })
开发者ID:cfaddict,项目名称:jhipster-course,代码行数:18,代码来源:register.component.spec.ts

示例5: fakeAsync

                fakeAsync((mockPrincipal: MockPrincipal, service: SessionsService) => {
                    mockPrincipal.spy('identity').and.returnValue(Promise.resolve({
                        id: 'fuzzer'
                    }));
                    spyOn(service, 'findAll').and.returnValue(Observable.of(sessions));

                    comp.ngOnInit();
                    tick();

                    expect(mockPrincipal.identitySpy).toHaveBeenCalled();
                    expect(service.findAll).toHaveBeenCalled();
                    expect(comp.success).toBeUndefined();
                    expect(comp.error).toBeUndefined();
                    expect(comp.account).toEqual({
                        id: 'fuzzer'
                    });
                    expect(comp.sessions).toEqual(sessions);
                })
开发者ID:JayRaparla,项目名称:jhipster,代码行数:18,代码来源:sessions.component.spec.ts

示例6: constructor7

 // retry pattern    
 constructor7() {
     var counter = 0;
     
     var ajaxCall = Observable.of('url')
         .delay(2000)
         .flatMap( () => {
             if (counter++ < 2) {
                 console.log("counter =", counter);                    
                 return Observable.throw(new Error("Request failed"));
             }
             return Observable.of([1,2,3]);
         });
     ajaxCall
         .retry(3)
         .subscribe(
         x => console.log(x),
         e => console.error(e)
     );        
 }
开发者ID:kwanling,项目名称:ng2test,代码行数:20,代码来源:app3.component.ts

示例7: getUser

	getUser():Observable<User>{

		if(this._user == undefined)
		{

			let headers = new Headers({ 'Content-Type': 'application/json' });
			let options = new RequestOptions({ headers: headers });

			this.applyTokenToHeader(options);

			return this.http.post(UserService.API + "/auth/verify",{},options).map(this.extractData).map((res) => {
				this._user = res;
				return this._user;
			});
		
		}

		return Observable.of<User>(this._user);
	}
开发者ID:SpacePorts,项目名称:CubesatDatabase,代码行数:19,代码来源:user-service.ts

示例8: login

 login(username: String) {
     this.http.post('http://localhost:8080/login', JSON.stringify({
             login: username
         }), {
             headers: new Headers({
                 'Content-Type': 'application/json'
             })
         })
         .map(res => res.json())
         .subscribe(
             res => this.token = res.token,
             err => console.log("Service is unavailable")
         );
     if(this.token == "failed") {
         this.token = undefined;
         return Observable.throw('authentication failure');
     }
     return Observable.of(this.token);
 }
开发者ID:DeJw92,项目名称:toik-lab,代码行数:19,代码来源:authentication.ts

示例9: it

    it('should return an observable', () => {
        const spy = jest.fn();

        const subt = {
            process(o) {
                return Observable.of(o);
            }
        }

        subt.process = jest.fn(subt.process);

        const t = new MapTransformer(subt);

        t.process(Observable.from([1]), 2)
            .subscribe(spy, null, () => {
                expect(spy.mock.calls.length).toBe(1);
                expect((subt.process as any).mock.calls.length).toBe(1);
            });
    });
开发者ID:smartive,项目名称:proc-that,代码行数:19,代码来源:MapTransformer.spec.ts

示例10: it

        it('should load the thumbnail preview of a pdf', (done) => {
            let blob = createFakePdfBlob();
            spyOn(serviceForm, 'getContentThumbnailUrl').and.returnValue(Observable.of(blob));

            component.thumbnailLoaded.subscribe((res) => {
                fixture.detectChanges();
                expect(res).toBeDefined();
                expect(res.changingThisBreaksApplicationSecurity).toBeDefined();
                expect(res.changingThisBreaksApplicationSecurity).toContain('blob');
                fixture.whenStable()
                    .then(() => {
                        let thumbnailPreview: any = element.querySelector('#thumbnailPreview');
                        expect(thumbnailPreview.src).toContain('blob');
                    });
                done();
            });

            let contentId = 1;
            let change = new SimpleChange(null, contentId, true);
            component.ngOnChanges({'id': change});

            jasmine.Ajax.requests.mostRecent().respondWith({
                status: 200,
                contentType: 'json',
                responseText: {
                    id: 4004,
                    name: 'FakeBlob.pdf',
                    created: 1490354907883,
                    createdBy: {
                        id: 2,
                        firstName: 'dasdas', 'lastName': 'dasads', 'email': 'administrator@admin.com'
                    },
                    relatedContent: false,
                    contentAvailable: true,
                    link: false,
                    mimeType: 'application/pdf',
                    simpleType: 'pdf',
                    previewStatus: 'created',
                    thumbnailStatus: 'created'
                }
            });
        });
开发者ID:gravitonian,项目名称:alfresco-ng2-components,代码行数:42,代码来源:content.widget.spec.ts


注:本文中的rxjs/Rx.Observable.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。