Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度:如何测试NgBootstrap模式组件_Angular_Angular5_Karma Jasmine - Fatal编程技术网

Angular 角度:如何测试NgBootstrap模式组件

Angular 角度:如何测试NgBootstrap模式组件,angular,angular5,karma-jasmine,Angular,Angular5,Karma Jasmine,我试图测试NgBoostrap模态组件,我使用的是NgbModal;它通过调用NgModal的open方法包装和呈现,该方法通过模板引用变量传递模态的内容。在测试中,我无法访问模型的内容,因此,我无法打开模型。如何测试此模式关闭和关闭功能 <button (click)="openDialog(formContent);" id="btnOpen"></button> 我怎样才能为此编写单元测试用例?在您的组件.ts文件中,您必须使用这样的东西 import { Ngb

我试图测试NgBoostrap模态组件,我使用的是NgbModal;它通过调用NgModal的open方法包装和呈现,该方法通过模板引用变量传递模态的内容。在测试中,我无法访问模型的内容,因此,我无法打开模型。如何测试此模式关闭和关闭功能

<button (click)="openDialog(formContent);" id="btnOpen"></button>

我怎样才能为此编写单元测试用例?

在您的
组件.ts
文件中,您必须使用这样的东西

import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-component',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent implements OnInit {

    constructor(private modalService: NgbModal, 
                private modalRef: NgbModalRef) {}

    ngOnInit() { }

    openDialog(content: any) {  // To open modal 
       this.modalRef = this.modalService.open(content, { centered: true, size: 'lg' });
    }

    closeModal() {  // To manually close modal
       this.modalRef.close();
    }

}

@jayraj-我在组件中也做了同样的工作,我的问题是如何为modal的功能编写单元测试用例(关闭和关闭)
 openDialog(content: any) {
  console.log('success');
 }, (reason) => {
  console.log('error');
 });
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-component',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent implements OnInit {

    constructor(private modalService: NgbModal, 
                private modalRef: NgbModalRef) {}

    ngOnInit() { }

    openDialog(content: any) {  // To open modal 
       this.modalRef = this.modalService.open(content, { centered: true, size: 'lg' });
    }

    closeModal() {  // To manually close modal
       this.modalRef.close();
    }

}