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

Bug: formatHtml on MockedComponentFixture / DebugElement won't give expected value #8203

Open
andreandersson opened this issue Feb 13, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@andreandersson
Copy link

andreandersson commented Feb 13, 2024

Description of the bug

When creating an Angular-component with MockRender, the actual component under testing becomes wrapped in another "dummy"-component. This creates a problem when you want to use ngMocks.formatHtml (and possibly formatText) to check if nothing is rendered within the component at all.

Our example is quite a bit bigger, but we listen to a service and render a template in a sidebar if there actually are anything emitted from the service. Now we want to test that logic, and formatHtml seems like it should be the correct way to do it.

An idea might be to check for isFixture here and somehow get the inner / actual component.

An example of the bug

Link: https://stackblitz.com/edit/github-lnydij?file=src%2Ftest.spec.ts

Expected vs actual behavior

Expected that ngMocks.formatHtml(MockRender(TargetComponent)) should return ''.

Actual is that ngMocks.formatHtml(MockRender(TargetComponent)) returns ''.

We can, in theory, test for the content to be ''. However, if you have any @input to the component it becomes difficult quite fast since the expectation might <app-target ng-reflect-text="TEST">TEST</app-target> instead. Also tried with fixture.debugElement but that seems to give the same result.

@andreandersson andreandersson added the bug Something isn't working label Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants