angular / angular

Deliver web apps with confidence 🚀
https://angular.dev
MIT License
94.88k stars 24.76k forks source link

Unit Testing guide has incorrect code #55386

Closed crfrolik closed 1 month ago

crfrolik commented 1 month ago

Describe the problem that you experienced

The example code shows this:

TestBed.configureTestingModule({ imports: [BannerComponent] });

However, it should be this:

TestBed.configureTestingModule({ declarations: [BannerComponent] });

Enter the URL of the topic with the problem

https://angular.io/guide/testing-components-basics#reduce-the-setup

Describe what you were looking for in the documentation

No response

Describe the actions that led you to experience the problem

No response

Describe what you want to experience that would fix the problem

No response

Add a screenshot if that helps illustrate the problem

No response

If this problem caused an exception or error, please paste it here

Error: Unexpected directive 'BannerComponent' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.
        at verifySemanticsOfNgModuleImport (node_modules/@angular/core/fesm2022/core.mjs:29800:19) [ProxyZone]
        at forEach (node_modules/@angular/core/fesm2022/core.mjs:29697:9) [ProxyZone]
        at Array.forEach (<anonymous>) [ProxyZone]
        at verifySemanticsOfNgModuleDef (node_modules/@angular/core/fesm2022/core.mjs:29696:60) [ProxyZone]
        at Function.get (node_modules/@angular/core/fesm2022/core.mjs:29649:30) [ProxyZone]
        at TestBedCompiler.applyProviderOverridesInScope (node_modules/@angular/core/fesm2022/testing.mjs:1152:33) [ProxyZone]
        at TestBedCompiler.compileTestModule (node_modules/@angular/core/fesm2022/testing.mjs:1447:14) [ProxyZone]
        at TestBedCompiler.finalize (node_modules/@angular/core/fesm2022/testing.mjs:977:14) [ProxyZone]
        at TestBedImpl.testModuleRef (node_modules/@angular/core/fesm2022/testing.mjs:1980:49) [ProxyZone]
        at TestBedImpl.inject (node_modules/@angular/core/fesm2022/testing.mjs:1884:29) [ProxyZone]
        at TestBedImpl.createComponent (node_modules/@angular/core/fesm2022/testing.mjs:1936:44) [ProxyZone]
        at Function.createComponent (node_modules/@angular/core/fesm2022/testing.mjs:1753:37) [ProxyZone]
        at Context.apply (...) [ProxyZone]


### If the problem is browser-specific, please specify the device, OS, browser, and version

_No response_

### Provide any additional information here in as much as detail as you can

_No response_
JeanMeche commented 1 month ago

The import is correct, BannerComponent is a standalone component.

angular-automatic-lock-bot[bot] commented 2 weeks ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.