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

MockInstance on component injected as a provider does not work for falsy values #2087

Closed
GerkinDev opened this issue Mar 17, 2022 · 4 comments · Fixed by #2096
Closed

MockInstance on component injected as a provider does not work for falsy values #2087

GerkinDev opened this issue Mar 17, 2022 · 4 comments · Fixed by #2096

Comments

@GerkinDev
Copy link

GerkinDev commented Mar 17, 2022

Hey there ! Hope you are doing well !

In one of my tests, a mocked component is injected as a provider in my actually tested component, and MockInstance seems to not work as expected: it does mock only truthy values, not falsy ones.

See the demo here: https://stackblitz.com/edit/github-ytvy85?file=src/test.spec.ts

What is strange is that the behavior is inconsistent:

  • either this is not how to test this situation, and thus, all tests should fail
  • or this is OK, and falsy values should be mocked too.

I think the problem comes from here: https://github.com/ike18t/ng-mocks/blob/0cfd6dc7f2cb2e95fdff3ca68433460e0a89f308/libs/ng-mocks/src/lib/mock-instance/mock-instance.ts#L182-L184

Footnote: You have links to stackblitz examples. What could be really cool would be to prepare a super trimmed down template for issues reporting, maybe even with both karma & jest presets, and request users to post a repro if possible in your issue template.

Have a nice day, and thanks again for the great lib ;)

@satanTime
Copy link
Member

Hi there! I do :) I hope :) and yourself?

Thanks for the report, I'll take a look on the upcoming weekend.

@GerkinDev
Copy link
Author

Yeah I've quite recently level up with ng-mocks, and it is really awesome, it's so pleasing to test using it !

No problem, no rush, I've found a way to avoid this issue by initializing my props with the falsy values by default, but I can't restore them to falsy.

@satanTime
Copy link
Member

Glad to hear about the level up :) Feel free to share thoughts and ideas you have.

satanTime added a commit to satanTime/ng-mocks that referenced this issue Mar 19, 2022
satanTime added a commit to satanTime/ng-mocks that referenced this issue Mar 19, 2022
satanTime added a commit that referenced this issue Mar 19, 2022
fix(MockInstance): correctly accepts falsy values #2087
@satanTime
Copy link
Member

v13.2.0 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
Development

Successfully merging a pull request may close this issue.

2 participants