角材料:无法读取未定义的属性“ openDialogs”

时间:2019-01-24 10:10:52

标签: angular angular-material

我正在尝试为使用MatDialog的组件编写测试。但是测试失败,并出现上述错误。

以下是有关错误发生位置的更多详细信息:

  at MatDialogTitle.Object.<anonymous>.MatDialogTitle.ngOnInit (node_modules/@angular/src/lib/dialog/dialog-content-directives.ts:91:73)
  at checkAndUpdateDirectiveInline (../packages/core/src/view/provider.ts:205:15)
  at checkAndUpdateNodeInline (../packages/core/src/view/view.ts:429:14)

我使用的是专有的Mocking-Framework,它可以模拟组件和指令。我想我必须在这些模拟上提供更多输入,以使MatDialog正常工作。

有人可以向我提示正确的方向吗?

1 个答案:

答案 0 :(得分:0)

Solved it:

I needed to provide a mock of the MatDialog-Class

  providers: [
    { provide: MatDialog, useClass: MockDialog },
  ],

with the according Mock:

class MockDialog {}

The MatDialog gets injected into the MatDialogTitle-Directive, therefore there has to be a MatDialog-Mock in the list of providers, otherwise it will be undefined.