最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NG0303: Can't bind to 'ngbTooltip' since it isn't a known property of 'butt

programmeradmin2浏览0评论

ERROR: 'NG0303: Can't bind to 'ngbTooltip' since it isn't a known property of 'button'.'

When I run tests locally for my Angular 12 project, I get this error, in all .spec files where ngbTooltip is used I use CUSTOM_ELEMENT_SCHEMA, it is impossible to track the line on which the error occurs. It is noteworthy that the error is absent with ng serve, but appears with ng test. Tell me how to solve this problem, I tried using CUSTOM_ELEMENT_SCHEMA in the application module, it did not help.

Console output Console output 2

ERROR: 'NG0303: Can't bind to 'ngbTooltip' since it isn't a known property of 'button'.'

When I run tests locally for my Angular 12 project, I get this error, in all .spec files where ngbTooltip is used I use CUSTOM_ELEMENT_SCHEMA, it is impossible to track the line on which the error occurs. It is noteworthy that the error is absent with ng serve, but appears with ng test. Tell me how to solve this problem, I tried using CUSTOM_ELEMENT_SCHEMA in the application module, it did not help.

Console output Console output 2

Share Improve this question edited Oct 13, 2021 at 22:15 Alex Kim asked Oct 13, 2021 at 19:05 Alex KimAlex Kim 331 silver badge4 bronze badges 2
  • Just add the CUSTOM_ELEMENT_SCHEMA in the related module.ts file – Aman Gojariya Commented Oct 13, 2021 at 20:08
  • It doesn't work, I already said it – Alex Kim Commented Oct 13, 2021 at 20:15
Add a ment  | 

1 Answer 1

Reset to default 5

Try adding NgbModule to imports array in TestBed.configureTestingModule({.

TestBed.configureTestingModule({
  imports: [NgbModule],
...

If you don't want to import NgbModule or it causes issues in your unit tests, you can mock the directive and provide the mock.

@Directive({
  selector: '[ngbTooltip]'
})
class MockNgbTooltip {}
...
TestBed.configureTestingModule({
  // add the mock to the declarations array
  declarations: [MockNgbTooltip],

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论