angular-testing-library icon indicating copy to clipboard operation
angular-testing-library copied to clipboard

Better types for RenderComponentOptions

Open Christian24 opened this issue 1 year ago • 0 comments

Hi,

I wish RenderComponentOptions were typed a little more. I have seen something along the lines of:

 const routingMock = new RouterMock()
        const ourPageMenuButtons: MenuButton[] = [{ name: 'testName', path: 'testPath' },
        { name: 'testName2', path: 'testPath2' }, { name: 'testName3', path: 'testPath3' }];
        await render(MenuComponent, {
            componentProviders: [ {provide: Router, usevalue: routingMock} ],
            componentProperties: {
                pageMenuButtons: ourPageMenuButtons
            }
        });

useValue isn't written correctly, there is no error in the static code analysis, because the actual type is just any[].

Maybe we can change it to something like:

export interface ProviderInterface {
  provide: any;
  useValue: any;
  multi?: boolean;
}
... RenderComponentOptions
imports?: Array<Type<any>|ModuleWithProviders<unknown>|any[]>;
providers?: Array<ProviderInterface | TypeProvider | EnvironmentProviders>;
componentProviders?: Array<ProviderInterface | TypeProvider | EnvironmentProviders>;

What do you think?

Christian24 avatar Sep 11 '23 18:09 Christian24