ng-mocks icon indicating copy to clipboard operation
ng-mocks copied to clipboard

Feature Request: Should ngMocks set signals mocks to singal(null) rather than null?

Open cford256 opened this issue 9 months ago • 2 comments

Given I use a signal in an html template like below

@Component({
  selector: 'app-component',
  template: '<h1>{{ count() }}</h1>',
})
export class AppComponent{
   count = signal(3);
}

And I want to have a mock version of it when testing a different component.

beforeAll(() => MockBuilder(OtherAppComponent, ItsModule) );

beforeEach(() => {
  const fixture = MockRender(OtherAppComponent);
});

Then I get an error along the lines of ctx.count is not a function. I believe this is because count is being set to null and then the template is trying to call it as a function. I am able to use Mock Instance to create a custom mock of the signal to avoid this. Was not sure if the way it currently works is the desired behavior.

Proposed solution

Instead of setting a signal mock to null, set it to signal(null).

cford256 avatar Oct 06 '23 22:10 cford256