简体   繁体   English

Karma / Jasmine测试不通过角度材料工具提示

[英]Karma/Jasmine test not passing with angular material tooltip

I am using a material design tooltip with the latest version of angular material design (beta 5). 我正在使用材料设计工具提示和最新版本的角度材料设计(beta 5)。

I attach the tooltip to a button this way: 我通过这种方式将工具提示附加到按钮:

<button id="{{module.action}}" md-raised-button (click)="onClick($event)" [mdTooltip] [disabled]="buttonDisabledState">
  {{module.text}}
</button>

And I have an Input property passed to the component: 我有一个传递给组件的Input属性:

export class ButtonComponent implements OnInit {
  @Input() module: ButtonModule;
  @Input() mdTooltip;

Everything goes well when running the local server, but if I run my test suites I keep receiving this error: 运行本地服务器时一切顺利,但如果我运行我的测试套件,我会一直收到此错误:

Can't bind to 'mdTooltip' since it isn't a known property of 'button'. ("th Dealflo Limited.
    -->
    <button id="{{module.action}}" md-raised-button (click)="onClick($event)" [ERROR ->][mdTooltip] [disabled]="buttonDisabledState">
      {{module.text}}
    </button>
    "): ng:///DynamicTestModule/ButtonComponent.html@13:74
    Error: Template parse errors:
    Can't bind to 'mdTooltip' since it isn't a known property of 'button'. ("th Dealflo Limited.
    -->
    <button id="{{module.action}}" md-raised-button (click)="onClick($event)" [ERROR ->][mdTooltip] [disabled]="buttonDisabledState">
      {{module.text}}
    </button>

I'm open to any idea here. 我对此有任何想法。

I think your button conflicts with the default html5 button. 我认为你的按钮与默认的html5按钮冲突。 The default has indeed no tooltip. 默认情况下确实没有工具提示。 Try changing your button selector. 尝试更改按钮选择器。

So after some investigation and trying different things, I came to a working solution! 经过一番调查和尝试不同的事情,我找到了一个有效的解决方案! Sharing it here for anybody that would experience the same issue. 在这里分享给任何会遇到同样问题的人。

I tried using creating a conditionnal attribute this way: 我试过用这种方式创建一个conditionnal属性:

[attr.mdTooltip]="module.tooltip? module.mdtooltip : ''"

Test passed but the tooltip was not showing. 测试通过但工具提示未显示。

I tried using an Input coming from the parent component alone and it worked perfectly: 我尝试使用来自父组件的输入,它完美地工作:

[mdTooltip]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM