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
CodePudding user response:
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],