Angular Ошибка теста: невозможно разрешить все параметры для MatDialogRef: (?,?,?,?) - PullRequest
0 голосов
/ 30 марта 2020

Я пытаюсь проверить диалоговое окно моего материала, но получаю ошибку, как указано ниже.

enter image description here

Здесь завершено Подтверждение-dialog.component. spe c .ts

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogRef, MatDialogModule, MAT_DIALOG_DATA, MatDialog  } from '@angular/material';

import { ConfirmDialogComponent } from './confirm-dialog.component';
import { SharedModule } from '../../shared.module';

describe('ConfirmDialogComponent', () => {
  let component: ConfirmDialogComponent;
  let fixture: ComponentFixture<ConfirmDialogComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ ConfirmDialogComponent ],
      imports: [ MatDialogModule ],
      providers : [ MatDialogRef ],
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(ConfirmDialogComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});

Я уже добавил свой ConfirmDialogComponent в entryComponents.

@NgModule({
  declarations: [
    ...pipes,
    ...components
  ],
  imports: [
    ...modules
  ],
  exports: [
    ...modules,
    ...pipes,
    ...components
  ],
  entryComponents: [
    ConfirmDialogComponent
  ]
})

Обновлено verify-dialog.component.ts

import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { ChangeDetectionStrategy, Component, HostListener, Inject, Output, OnInit } from '@angular/core';

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: 'app-confirm-dialog',
  templateUrl: './confirm-dialog.component.html',
  styleUrls: ['./confirm-dialog.component.scss']
})
export class ConfirmDialogComponent implements OnInit {
  title: string;
  message: string;

  constructor(
    public dialogRef: MatDialogRef<ConfirmDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: ConfirmDialogModel
    ) {
    // Update view with given values
    // this.title = data.title;
    // this.message = data.message;
  }

  ngOnInit() {
  }

  public onClose(value) {
    this.dialogRef.close(value);
  }

  public onCancel(): void {
    this.onClose(false);
  }

  public onConfirm(): void {
    // Close the dialog, return true
    this.dialogRef.close(true);
  }

  public onDismiss(): void {
    // Close the dialog, return false
    this.dialogRef.close(false);
  }

  @HostListener('keydown.esc')
  public onEsc() {
    this.onClose(false);
  }
}

/**
 * Class to represent confirm dialog model.
 *
 * It has been kept here to keep it as part of shared component.
 */
export class ConfirmDialogModel {

  constructor(
    public title: string,
    public message: string,
    public cancelText: string,
    public confirmText: string
    ) {
  }
}

Я пытался найти, но не смог найти решение, которое мне подходит.

Заранее спасибо.

...