3

I am using ng-mocks with Angular. While running the test case, I am getting below error

console.error NG0304: 'ng-mocks-ButtonComponent' is not a known element (used in the 'i' component > template):

  1. If 'ng-mocks-ButtonComponent' is an Angular component, then verify that it is a part > of an @NgModule where this component is declared.
  2. If 'ng-mocks-ButtonComponent' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to > the '@NgModule.schemas' of this component to suppress this message.
describe('ButtonComponent', () => {
  beforeEach(() => {
    return MockBuilder(ButtonComponent, ButtonModule);
  });

  it('should create', () => {
    const fixture = MockRender(ButtonComponent);
    expect(fixture.point.componentInstance).toBeDefined();
  });

  it('should have icon as input decorator for the button component', () => {
    const fixture = MockRender(ButtonComponent);
    expect(fixture.point.componentInstance.icon).toBeDefined();
  });
  • Test setup looks fine, can we also see ButtonComponent? – tjkeast Sep 28 '22 at 07:50
  • ``` @Component({ selector: 'button[my-button]', exportAs: 'myButton', styleUrls: [ './button.component.scss'], templateUrl: './button.component.html', encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, }) export class ButtonComponent implements OnInit { @Input() btnIcon; @Input() btnType; } ``` – user2148340 Sep 28 '22 at 10:30
  • Perhaps try `selector: 'my-button'` and see if the same error occurs. Something odd is happening with the component name since the error mentions `'ng-mocks-ButtonComponent'` – tjkeast Sep 28 '22 at 21:04
  • Could you share the decoration of the component? Also, which version of `ng-mocks` do you use? – satanTime Oct 10 '22 at 07:20

1 Answers1

0

This issue has been reported and fixed already: https://github.com/help-me-mom/ng-mocks/issues/3515

Please upgrade ng-mock to the latest version.

satanTime
  • 12,631
  • 1
  • 25
  • 73