使用DebugElement获取按钮元素不起作用

时间:2019-05-17 13:04:55

标签: html5 jasmine angular5 karma-runner

我正在尝试测试按钮单击。当我尝试使用By.css从debug元素获取按钮时,得到的结果为null:

describe('Register2Component', () => {
  let component: FuseResetPassword2Component;
  let debugElement: DebugElement;
  let fixture: ComponentFixture<FuseResetPassword2Component>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        ReactiveFormsModule,
        FormsModule,
        MaterialModule,
        TranslateModule.forRoot(),
        RouterTestingModule.withRoutes(
          [{path: 'apps/auth/reset-password', component: FuseResetPassword2Component}]
        ),
        HttpClientModule,
        FuseSharedModule
      ],
      declarations: [FuseResetPassword2Component],
      providers: [
        FormBuilder, UsersService, FormBuilder, FuseConfigService,
        FuseTranslationLoaderService,
        {provide: APP_BASE_HREF, useValue: '/apps/auth/reset-password'},
      ]
    })
      .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(FuseResetPassword2Component);
    component = fixture.componentInstance;
    fixture.detectChanges();
    fixture.checkNoChanges();
    debugElement = fixture.debugElement;
    component.ngOnInit();

  });

  it('should create', () => {
    expect(component).toBeTruthy();
    console.log('------', fixture.debugElement.nativeElement.getElementsByTagName('button'));
    console.log(fixture.debugElement.query(By.css('button')));
  });


});

我期望按钮元素的结果,但我为空

0 个答案:

没有答案