Title: Bug (or Docs Bug?): Unable to test recursive standalone component due to NG0300 · Issue #50525 · angular/angular · GitHub
Open Graph Title: Bug (or Docs Bug?): Unable to test recursive standalone component due to NG0300 · Issue #50525 · angular/angular
X Title: Bug (or Docs Bug?): Unable to test recursive standalone component due to NG0300 · Issue #50525 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description I have a relatively simple component that recursively nests on itself to build a node tree of div tags with various css classes and inner t...
Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description I have a relatively simple component that recursively nests on itself to build a node tree of div t...
X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description I have a relatively simple component that recursively nests on itself to build a node tree of div t...
Opengraph URL: https://github.com/angular/angular/issues/50525
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug (or Docs Bug?): Unable to test recursive standalone component due to NG0300","articleBody":"### Which @angular/* package(s) are the source of the bug?\r\n\r\ncore\r\n\r\n### Is this a regression?\r\n\r\nYes\r\n\r\n### Description\r\n\r\nI have a relatively simple component that recursively nests on itself to build a node tree of div tags with various css classes and inner text based on a configuration object. When I convert this component to a standalone component, my tests fail with NG0300 but the new component works fine in the application. I'm assuming I am doing something wrong in configuring the testing module or that there is some bug in it but I'm unable to find documentation covering this case. The full component:\r\n\r\n```typescript\r\nimport { Input, Component, forwardRef } from '@angular/core';\r\nimport { NgFor, NgIf, NgClass } from '@angular/common';\r\n\r\nexport interface Node {\r\n cssClasses?: string;\r\n text?: string;\r\n nodes?: Node[];\r\n}\r\n\r\n@Component({\r\n selector: '[app-nester]',\r\n template: `\u003cng-container *ngFor=\"let node of nodes\">\r\n \u003cng-container>\r\n \u003cng-container *ngIf=\"node.text as text\">\r\n \u003cdiv [ngClass]=\"node.cssClasses!\">{{ text }}\u003c/div>\r\n \u003c/ng-container>\r\n \u003cng-container *ngIf=\"node.nodes as nodes\">\r\n \u003cdiv [ngClass]=\"node.cssClasses!\" app-nester [nodes]=\"node.nodes\">\u003c/div>\r\n \u003c/ng-container>\r\n \u003c/ng-container>\r\n \u003c/ng-container> `,\r\n // standalone: true,\r\n // imports: [NgFor, NgIf, NgClass, forwardRef(() => NesterComponent)],\r\n})\r\nexport class NesterComponent {\r\n @Input() nodes: Node[] | null = null;\r\n}\r\n```\r\n\r\nto convert to standalone I used the new migration and it added these commented out lines and imports.\r\n\r\nMy Tests:\r\n\r\n```typescript\r\nimport { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';\r\n\r\nimport { NesterComponent } from './nester.component';\r\n\r\ndescribe('NesterComponent', () => {\r\n let component: NesterComponent;\r\n let fixture: ComponentFixture\u003cNesterComponent>;\r\n\r\n // remove for standalone version\r\n beforeEach(waitForAsync(() => {\r\n TestBed.configureTestingModule({ declarations: [NesterComponent] }).compileComponents();\r\n }));\r\n\r\n // standalone version from migration:\r\n // beforeEach(waitForAsync(() => {\r\n // TestBed.configureTestingModule({ imports: [NesterComponent] }).compileComponents();\r\n // }));\r\n\r\n beforeEach(() => {\r\n fixture = TestBed.createComponent(NesterComponent);\r\n component = fixture.componentInstance;\r\n fixture.detectChanges();\r\n });\r\n\r\n it('should create', () => {\r\n expect(component).toBeDefined();\r\n });\r\n\r\n it('should render text', () => {\r\n component.nodes = [\r\n { cssClasses: 'test1', text: 'test1' },\r\n {\r\n cssClasses: 'test2',\r\n nodes: [{ cssClasses: 'not in result' }, { text: 'test4' }],\r\n },\r\n {\r\n cssClasses: 'test5',\r\n nodes: [],\r\n },\r\n ];\r\n fixture.detectChanges();\r\n expect(fixture.nativeElement).toMatchSnapshot();\r\n });\r\n});\r\n```\r\n\r\nAgain in this case all the migration did was change `declarations` to `imports`\r\n\r\nThe above functions and test passes... however if I switch it to the standalone version of both files then the test fails (as far as I can tell it still works though, this is just a test problem).\r\n\r\n### Please provide a link to a minimal reproduction of the bug\r\n\r\n_No response_\r\n\r\n### Please provide the exception or error you saw\r\n\r\n```\r\nFAIL src/app/shared/nester/nester.component.spec.ts (13.262 s)\r\n NesterComponent\r\n √ should create (322 ms)\r\n × should render text (826 ms)\r\n\r\n ● NesterComponent › should render text\r\n\r\n NG0300: Multiple components match node with tagname div: NesterComponent and NesterComponent. Find more at https://angular.io/errors/NG0300\r\n\r\n at throwMultipleComponentError (node_modules/@angular/core/fesm2022/core.mjs:10251:11)\r\n at findDirectiveDefMatches (node_modules/@angular/core/fesm2022/core.mjs:11580:29)\r\n at resolveDirectives (node_modules/@angular/core/fesm2022/core.mjs:11380:29)\r\n at elementStartFirstCreatePass (node_modules/@angular/core/fesm2022/core.mjs:15137:5)\r\n at ɵɵelementStart (node_modules/@angular/core/fesm2022/core.mjs:15173:9)\r\n at ɵɵelement (node_modules/@angular/core/fesm2022/core.mjs:15254:5)\r\n at NesterComponent_ng_container_0_ng_container_1_ng_container_2_Template (ng:/NesterComponent.js:25:5)\r\n at executeTemplate (node_modules/@angular/core/fesm2022/core.mjs:10890:17)\r\n at renderView (node_modules/@angular/core/fesm2022/core.mjs:12078:13)\r\n at TemplateRef2.createEmbeddedViewImpl (node_modules/@angular/core/fesm2022/core.mjs:22877:9)\r\n at ViewContainerRef2.createEmbeddedView (node_modules/@angular/core/fesm2022/core.mjs:23142:37)\r\n at _NgIf._updateView (node_modules/@angular/common/fesm2022/common.mjs:3316:45)\r\n at _NgIf.set ngIf [as ngIf] (node_modules/@angular/common/fesm2022/common.mjs:3289:14)\r\n at writeToDirectiveInput (node_modules/@angular/core/fesm2022/core.mjs:11766:33)\r\n at setInputsForProperty (node_modules/@angular/core/fesm2022/core.mjs:12000:9)\r\n at elementPropertyInternal (node_modules/@angular/core/fesm2022/core.mjs:11302:9)\r\n at ɵɵproperty (node_modules/@angular/core/fesm2022/core.mjs:15115:9)\r\n at NesterComponent_ng_container_0_ng_container_1_Template (ng:/NesterComponent.js:48:5)\r\n at ReactiveLViewConsumer.runInContext (node_modules/@angular/core/fesm2022/core.mjs:10345:13)\r\n at executeTemplate (node_modules/@angular/core/fesm2022/core.mjs:10885:22)\r\n at refreshView (node_modules/@angular/core/fesm2022/core.mjs:12395:13)\r\n at refreshEmbeddedViews (node_modules/@angular/core/fesm2022/core.mjs:12506:17)\r\n at refreshView (node_modules/@angular/core/fesm2022/core.mjs:12419:9)\r\n at refreshEmbeddedViews (node_modules/@angular/core/fesm2022/core.mjs:12506:17)\r\n at refreshView (node_modules/@angular/core/fesm2022/core.mjs:12419:9)\r\n at refreshComponent (node_modules/@angular/core/fesm2022/core.mjs:12542:13)\r\n at refreshChildComponents (node_modules/@angular/core/fesm2022/core.mjs:12589:9)\r\n at refreshView (node_modules/@angular/core/fesm2022/core.mjs:12445:13)\r\n at detectChangesInternal (node_modules/@angular/core/fesm2022/core.mjs:12337:9)\r\n at RootViewRef.detectChanges (node_modules/@angular/core/fesm2022/core.mjs:12867:9)\r\n at ComponentFixture._tick (node_modules/@angular/core/fesm2022/testing.mjs:126:32)\r\n at node_modules/@angular/core/fesm2022/testing.mjs:139:22\r\n at _ZoneDelegate.Object.\u003canonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:416:30)\r\n at ProxyZoneSpec.Object.\u003canonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/bundles/zone-testing.umd.js:300:43)\r\n at _ZoneDelegate.Object.\u003canonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:415:56)\r\n at Object.onInvoke (node_modules/@angular/core/fesm2022/core.mjs:26108:33)\r\n at _ZoneDelegate.Object.\u003canonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:415:56)\r\n at Zone.Object.\u003canonymous>.Zone.run (node_modules/zone.js/bundles/zone.umd.js:173:47)\r\n at NgZone.run (node_modules/@angular/core/fesm2022/core.mjs:25962:28)\r\n at ComponentFixture.detectChanges (node_modules/@angular/core/fesm2022/testing.mjs:138:25)\r\n at src/app/shared/nester/nester.component.spec.ts:37:13\r\n at _ZoneDelegate.Object.\u003canonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:416:30)\r\n at ProxyZoneSpec.Object.\u003canonymous>.ProxyZoneSpec.onInvoke (node_modules/zone.js/bundles/zone-testing.umd.js:300:43)\r\n at _ZoneDelegate.Object.\u003canonymous>._ZoneDelegate.invoke (node_modules/zone.js/bundles/zone.umd.js:415:56)\r\n at Zone.Object.\u003canonymous>.Zone.run (node_modules/zone.js/bundles/zone.umd.js:173:47)\r\n at Object.wrappedFunc (node_modules/zone.js/bundles/zone-testing.umd.js:780:34)\r\n```\r\n\r\n\r\n\r\n### Please provide the environment you discovered this bug in (run `ng version`)\r\n\r\n```true\r\nAngular CLI: 16.0.2\r\nNode: 18.16.0\r\nPackage Manager: npm 9.5.1\r\nOS: win32 x64\r\n\r\nAngular: 16.0.2\r\n... animations, cli, common, compiler, compiler-cli, core, forms\r\n... language-service, localize, platform-browser\r\n... platform-browser-dynamic, router\r\n\r\nPackage Version\r\n@angular-devkit/architect 0.1502.6\r\n@angular-devkit/build-angular 16.0.2\r\n@angular-devkit/core 15.2.6\r\n@angular-devkit/schematics 16.0.2\r\n@angular/cdk 16.0.1\r\n@angular/material 16.0.1\r\n@schematics/angular 16.0.2\r\nrxjs 7.8.1\r\ntypescript 5.0.4\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\nIt would be nice if https://angular.io/guide/testing-components-basics said something about standalone components. And/Or if https://angular.io/guide/standalone-components or https://angular.io/guide/standalone-migration covered testing at all.","author":{"url":"https://github.com/bbarry","@type":"Person","name":"bbarry"},"datePublished":"2023-05-30T20:54:47Z","url":"https://github.com/angular/angular/issues/50525"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3cd2f9c8-05aa-e923-7f9f-3ec01da9425f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B34:91CF4:19D858D:222CF8B:6B01437A |
| html-safe-nonce | aa6c814c06357c9a7a9e9803c3494b60ad67ee086767212f8cf9fd3b6326a8ea |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjM0OjkxQ0Y0OjE5RDg1OEQ6MjIyQ0Y4Qjo2QjAxNDM3QSIsInZpc2l0b3JfaWQiOiI2Nzk3OTg0NjUwODE2ODA1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1d0d739867d9f7ed302af48d8544f801bcfd36492c22838003a52dff5c66fa01 |
| hovercard-subject-tag | issue:1732997975 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/50525/issue_layout |
| twitter:image | https://opengraph.githubassets.com/135c84a8345c2663b62d15f6a79fe6127f18abea9e35dbcca95e094e82a4db45/angular/angular/issues/50525 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/135c84a8345c2663b62d15f6a79fe6127f18abea9e35dbcca95e094e82a4db45/angular/angular/issues/50525 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? core Is this a regression? Yes Description I have a relatively simple component that recursively nests on itself to build a node tree of div t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bbarry |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width