本文整理汇总了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);
});
示例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;
});
示例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();
})
示例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();
})
示例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);
})
示例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)
);
}
示例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);
}
示例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);
}
示例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);
});
});
示例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'
}
});
});