Angular Unit Test Error: No Component Factory Found For Component. Did You Add It To @NgModule.entryComponents


Answer :

Testing is doubting.

More seriously, let me answer you.

In Angular, your components are handled by a module. When you use Material dialogs and snackers, you actually use a feature of the CDK, which is called Portal. This allow you to create your components dynamically.

But when you do so, you have to add them to the entryComponents of your module. You did it in your module, so you should also do it in your tests.

The syntax is

TestBed   .configureTestingModule(...)   .overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [YourComponent] } }); 

there are two places at which this is supposed to be done....entry components and also at declarations(while configuring your testing module)....

  TestBed   .configureTestingModule({               declarations: [YourComponent],    })   .overrideModule(BrowserDynamicTestingModule, { set: { entryComponents: [YourComponent] } }); 

If someone struggling to find BrowserDynamicTestingModule just use BrowserModule instead.

   TestBed   .configureTestingModule(...)   .overrideModule(BrowserModule, { set: { entryComponents: [YourComponent] } }); 

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable