feat(core): add option to infer the tag names of components in tests#62283
Closed
crisbeto wants to merge 2 commits intoangular:mainfrom
Closed
feat(core): add option to infer the tag names of components in tests#62283crisbeto wants to merge 2 commits intoangular:mainfrom
crisbeto wants to merge 2 commits intoangular:mainfrom
Conversation
thePunderWoman
approved these changes
Jun 26, 2025
| // Note: injecting the renderer before accessing the definition appears to be load-bearing. | ||
| const testComponentRenderer = this.inject(TestComponentRenderer); | ||
| const componentDef: ComponentDef<T> = (type as any).ɵcmp; | ||
| const rootElId = `root${_nextRootElementId++}`; |
Contributor
There was a problem hiding this comment.
Optional nit: It'd be nice to have a comment for the next two lines explaining what this is doing.
devversion
approved these changes
Jun 26, 2025
Member
devversion
left a comment
There was a problem hiding this comment.
LGTM
Reviewed-for: public-api
Exposes the code that we use to infer the tag name of a component as a private export so that we can use it in `TestBed`.
ba6cba3 to
3f210b0
Compare
Member
Author
|
I've reworked this PR with the following changes:
|
devversion
approved these changes
Jul 23, 2025
Currently when testing a component using `TestBed.createComponent`, we always create the component as a `div` which isn't aligned with the runtime. The runtime tries to parse out the tag name from the first selector in `@Component` and only falls back to `div` if there isn't one. This behavior difference can cause components to not behave like they would in production which reduces the usefulness of the tests. These changes add the `inferTagName` option to `TestBed.createComponent` and `TestBed.configureTestingModule` that allows apps to opt into inferring the tag name from the selector in the same way as the runtime. Currently the new option is set to `false`, but we intend to change it to `true` in a future version.
3f210b0 to
4458318
Compare
Contributor
|
This PR was merged into the repository by commit cec91c0. The changes were merged into the following branches: main |
kirjs
pushed a commit
that referenced
this pull request
Jul 23, 2025
…62283) Currently when testing a component using `TestBed.createComponent`, we always create the component as a `div` which isn't aligned with the runtime. The runtime tries to parse out the tag name from the first selector in `@Component` and only falls back to `div` if there isn't one. This behavior difference can cause components to not behave like they would in production which reduces the usefulness of the tests. These changes add the `inferTagName` option to `TestBed.createComponent` and `TestBed.configureTestingModule` that allows apps to opt into inferring the tag name from the selector in the same way as the runtime. Currently the new option is set to `false`, but we intend to change it to `true` in a future version. PR Close #62283
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently when testing a component using
TestBed.createComponent, we always create the component as adivwhich isn't aligned with the runtime. The runtime tries to parse out the tag name from the first selector in@Componentand only falls back todivif there isn't one. This behavior difference can cause components to not behave like they would in production which reduces the usefulness of the tests.These changes add the
inferTagNameoption toTestBed.createComponentandTestBed.configureTestingModulethat allows apps to opt into inferring the tag name from the selector in the same way as the runtime. Currently the new option is set tofalse, but we intend to change it totruein a future version.