• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript testing.ComponentFixture类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript testing.Log类代码示例发布时间:2022-05-28
下一篇:
TypeScript testing.xit函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap