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


TypeScript testing.ComponentFixture类代码示例

本文整理汇总了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');
//.........这里部分代码省略.........
开发者ID:dillaman,项目名称:ceph,代码行数:101,代码来源:rbd-list.component.spec.ts

示例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');
    });
  });
});
开发者ID:kensodemann,项目名称:time-trax,代码行数:61,代码来源:ask-dialog.service.spec.ts

示例3: beforeEach

 beforeEach(() => {
   fixture = TestBed.createComponent(BookingErrorComponent);
   component = fixture.componentInstance;
   fixture.detectChanges();
 });
开发者ID:bwhiting2356,项目名称:fiits,代码行数:5,代码来源:booking-error.component.spec.ts

示例4: beforeEach

 beforeEach(() => {
   fixture = TestBed.createComponent(TofaDataComponent);
   component = fixture.componentInstance;
   fixture.detectChanges();
 });
开发者ID:usha29,项目名称:Angular4,代码行数:5,代码来源:tofa-data.component.spec.ts

示例5: beforeEach

 beforeEach(() => {
   fixture = TestBed.createComponent(ListSurveyComponent);
   component = fixture.componentInstance;
   fixture.detectChanges();
 });
开发者ID:virendrasinghpawar,项目名称:survey,代码行数:5,代码来源:list-survey.component.spec.ts

示例6: afterEach

 afterEach(() => {
   fixture.destroy();
 });
开发者ID:cmgustavo,项目名称:copay,代码行数:3,代码来源:pin-modal.spec.ts

示例7: beforeEach

 beforeEach(() => {
   fixture = TestBed.createComponent(ComponentDeleteDialogComponent);
   component = fixture.componentInstance;
   fixture.detectChanges();
 });
开发者ID:openfact,项目名称:openfact-web-console,代码行数:5,代码来源:component-delete-dialog.component.spec.ts

示例8: beforeEach

 beforeEach(() => {
     fixture = TestBed.createComponent(CategorySortComponent);
     component = fixture.componentInstance;
     fixture.detectChanges();
 });
开发者ID:CatoTH,项目名称:OpenSlides,代码行数:5,代码来源:category-sort.component.spec.ts

示例9: beforeEach

 beforeEach(() => {
   fixture = TestBed.createComponent(NewClusterComponent);
   component = fixture.componentInstance;
   fixture.detectChanges();
 });
开发者ID:briansage,项目名称:supergiant,代码行数:5,代码来源:new-cluster.component.spec.ts

示例10:

 state.skip(1).take(1).subscribe(() => fixture.detectChanges());
开发者ID:Blackbaud-DanHamlin,项目名称:skyux2,代码行数:1,代码来源:list-column-selector-action.spec.ts


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