0
@Component({
  selector: 'app-entity-details',
  templateUrl: './entity-details.component.html',
  styleUrls: ['./entity-details.component.scss'],
  viewProviders: [{
    provide: ControlContainer,
    useFactory: (container: ControlContainer) => container,
    deps: [[new SkipSelf(), ControlContainer]],
  }]
})
export class EntityDetailsComponent{

I have found the above setup using viewProviders on my Component as a way to use nested Formgroups within nestes Components without manually handling those as Input and/or output. Now I am trying to figure out how to setup my test environment in the spec files.

Currently I obviously get a "No provider found for 'ControlContainer'" error. Configuring the TestingModule to provide the exact same thing I use about or even a generic ControlContainer does not yield any results. Do I have to mock a new Component that uses my EntityDetailsComponent?

I am thankful for any sources that might help.

Chund
  • 355
  • 2
  • 15

1 Answers1

1

Edit

First check out this link, I think it can help you more.

Edit over

Try mocking it:

let mockControlContainer;
....
// This (mockControlerContainer = ) should be at the beginning of your first beforeEach
// The first string is the identifier (can be anything) and the second array of strings
// are public methods you would like to mock for ControlContainer.
// I put 'public', 'methods' but you can change them to anything you like.
mockControlContainer = jasmine.createSpyObj('container', ['public', 'methods']);
...
TestBed.configureTestingModule({
  imports: [], // put in imports what is needed
  declarations: [EntityDetailsComponent],
  // provide the mockControlContainer
  providers: [{ provide: ControlContainer, useValue: mockControlContainer }]
});

If ControlContainer does not have any dependencies and can be easily mocked, you should be able to provide it directly:

TestBed.configureTestingModule({
  imports: [], // put in imports what is needed
  declarations: [EntityDetailsComponent],
  // provide the mockControlContainer
  providers: [ControlContainer]
});
AliF50
  • 16,947
  • 1
  • 21
  • 37
  • 1
    I have no idea why i didn't think about it, but yes mocking it did the trick. Stupid me :D Thanks a lot – Chund Apr 29 '21 at 07:53