本文整理汇总了TypeScript中@angular/core/testing.ComponentFixture类的典型用法代码示例。如果您正苦于以下问题:TypeScript ComponentFixture类的具体用法?TypeScript ComponentFixture怎么用?TypeScript ComponentFixture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComponentFixture类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('RbdListComponent', () => {
let fixture: ComponentFixture<RbdListComponent>;
let component: RbdListComponent;
let summaryService: SummaryService;
let rbdService: RbdService;
const refresh = (data) => {
summaryService['summaryDataSource'].next(data);
};
configureTestBed({
imports: [
SharedModule,
BsDropdownModule.forRoot(),
TabsModule.forRoot(),
ModalModule.forRoot(),
TooltipModule.forRoot(),
ToastModule.forRoot(),
AlertModule.forRoot(),
ComponentsModule,
RouterTestingModule,
HttpClientTestingModule
],
declarations: [RbdListComponent, RbdDetailsComponent, RbdSnapshotListComponent],
providers: [SummaryService, TaskListService, RbdService]
});
beforeEach(() => {
fixture = TestBed.createComponent(RbdListComponent);
component = fixture.componentInstance;
summaryService = TestBed.get(SummaryService);
rbdService = TestBed.get(RbdService);
// this is needed because summaryService isn't being reset after each test.
summaryService['summaryDataSource'] = new BehaviorSubject(null);
summaryService['summaryData$'] = summaryService['summaryDataSource'].asObservable();
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('after ngOnInit', () => {
beforeEach(() => {
fixture.detectChanges();
spyOn(rbdService, 'list').and.callThrough();
});
it('should load images on init', () => {
refresh({});
expect(rbdService.list).toHaveBeenCalled();
});
it('should not load images on init because no data', () => {
refresh(undefined);
expect(rbdService.list).not.toHaveBeenCalled();
});
it('should call error function on init when summary service fails', () => {
spyOn(component.table, 'reset');
summaryService['summaryDataSource'].error(undefined);
expect(component.table.reset).toHaveBeenCalled();
expect(component.viewCacheStatusList).toEqual([{ status: ViewCacheStatus.ValueException }]);
});
});
describe('handling of executing tasks', () => {
let images: RbdModel[];
const addImage = (name) => {
const model = new RbdModel();
model.id = '-1';
model.name = name;
model.pool_name = 'rbd';
images.push(model);
};
const addTask = (name: string, image_name: string) => {
const task = new ExecutingTask();
task.name = name;
task.metadata = {
pool_name: 'rbd',
image_name: image_name,
child_pool_name: 'rbd',
child_image_name: 'd',
dest_pool_name: 'rbd',
dest_image_name: 'd'
};
summaryService.addRunningTask(task);
};
const expectImageTasks = (image: RbdModel, executing: string) => {
expect(image.cdExecuting).toEqual(executing);
};
beforeEach(() => {
images = [];
addImage('a');
addImage('b');
addImage('c');
//.........这里部分代码省略.........
示例2: describe
describe('AskDialogService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [MdDialogModule, DialogTestModule],
providers: [AskDialogService],
});
});
let service;
let testViewContainerRef: ViewContainerRef;
let viewContainerFixture: ComponentFixture<ChildViewContainerComponent>;
beforeEach(inject([AskDialogService], (s: AskDialogService) => { service = s; }));
beforeEach(() => {
viewContainerFixture = TestBed.createComponent(ChildViewContainerComponent);
viewContainerFixture.detectChanges();
testViewContainerRef = viewContainerFixture.componentInstance.childViewContainer;
});
it('exists', () => { expect(service).toBeTruthy(); });
describe('open', () => {
let dialog;
let dialogRef;
beforeEach(() => {
dialog = viewContainerFixture.debugElement.injector.get(MdDialog);
dialogRef = {
componentInstance: {
title: '',
message: ''
},
afterClosed: () => Observable.empty()
};
spyOn(dialog, 'open').and.returnValue(dialogRef);
});
it('opens the dialog', () => {
service.open('title', 'message', testViewContainerRef);
expect(dialog.open).toHaveBeenCalledTimes(1);
});
it('sets the title', () => {
service.open('title', 'message', testViewContainerRef);
expect(dialogRef.componentInstance.title).toEqual('title');
});
it('sets the message', () => {
service.open('title', 'message', testViewContainerRef);
expect(dialogRef.componentInstance.message).toEqual('message');
});
it('returns the after closed observable', () => {
dialogRef.afterClosed = () => Observable.of('toast');
let result: string;
service.open('title', 'message', null).subscribe(res => result = res);
expect(result).toEqual('toast');
});
});
});
示例3: beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(BookingErrorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
示例4: beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(TofaDataComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
示例5: beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(ListSurveyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
示例6: afterEach
afterEach(() => {
fixture.destroy();
});
示例7: beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(ComponentDeleteDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
示例8: beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(CategorySortComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
示例9: beforeEach
beforeEach(() => {
fixture = TestBed.createComponent(NewClusterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
示例10:
state.skip(1).take(1).subscribe(() => fixture.detectChanges());