Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking a Standalone Component without a Selector does not mock the imports #4032

Closed
Simon-TheHelpfulCat opened this issue Oct 29, 2022 · 2 comments · Fixed by #4037
Closed

Comments

@Simon-TheHelpfulCat
Copy link

A minimal reproduction:

import { CommonModule } from "@angular/common";
import { Component } from "@angular/core";
import { RouterModule } from "@angular/router";
import { MockBuilder, MockRender } from "ng-mocks";

@Component({
  selector: "my-test-one",
  standalone: true,
  imports: [CommonModule, RouterModule],
  template: `<a [routerLink]="['test']">Test</a>`
})
class TestOneComponent {}

@Component({
  standalone: true,
  imports: [CommoBoth ytestsnModule, RouterModule],
  template: `<a [routerLink]="['test']">Test</a>`
})
class TestTwoComponent {}

describe("with selector", () => {
  beforeEach(() => MockBuilder(TestOneComponent));

  it("should render", () => {
    expect(MockRender(TestOneComponent).point.componentInstance).toBeDefined();
  });
});

describe("witout selector", () => {
  beforeEach(() => MockBuilder(TestTwoComponent));

  it("should render", () => {
    expect(MockRender(TestTwoComponent).point.componentInstance).toBeDefined();
  });
});

Both tests pass, but looking in the console you see:

NG0303: Can't bind to 'routerLink' since it isn't a known property of 'a' (used in the 'MockMiddlewareTestTwoComponent' component template).

Adding a selector to TextTwoComponent or adding .mock(RouterModule)) to the MockBuilder removes this message.

This minimal reproduction is reproduced in Code Sandbox.

@satanTime
Copy link
Member

Hi @Simon-TheHelpfulCat,

thanks for the report!

satanTime added a commit to satanTime/ng-mocks that referenced this issue Oct 30, 2022
satanTime added a commit to satanTime/ng-mocks that referenced this issue Oct 30, 2022
satanTime added a commit to satanTime/ng-mocks that referenced this issue Oct 30, 2022
satanTime added a commit that referenced this issue Oct 30, 2022
fix(MockRender): respecting customizations for declarations without selectors #4032
@satanTime
Copy link
Member

v14.3.2 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants