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

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

Open
cford256 opened this issue Oct 6, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@cford256
Copy link

cford256 commented Oct 6, 2023

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 cford256 added the enhancement New feature or request label Oct 6, 2023
@satanTime
Copy link
Member

satanTime commented Nov 15, 2023

Hi @cford256,

that's a good FR. I'll take a look how it's possible to detect signals to mock them.

At this moment, I would recommend something like default observables:

ngMocks.defaultMock(TodoService, () => ({
  count : signal(),
}));

@cford256
Copy link
Author

Good Idea, I think that I could simplify my code a bit with the help of that function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants