'How do I deal with testing a service that uses a large configuration object?

If I component that has a large configuration object that is intended to be used by several internal services, but an individual service may only be interested in one or two properties in this config... How do I deal with testing this?

In my test, I was trying to just pass in a Partial<MyLargeConfig> with only the relevant properties set, but I get errors about a property being optional for the partial, but required in the actual interface.

How can I get around this without having to have my tests declare some obnoxious config object with all the properties set? Is there any way to tell typescript to allow a partial in the context of my tests only?

I would like to avoid having to add ? to the end of all the properties... That seems like the wrong solution. Declaring all the properties in the test also seems like the wrong solution.

*** EDIT ***

To make this less abstract (yet still somewhat abstract), what I am doing is, building a configuration object and passing it to a component such as:

interface MyLargeConfig {
  a: string,
  b: number,
  c: boolean,
  d: () => void,
  e: ...etc
}
<my-component [config]="config"></my-component>

and then the component internally would be doing

this.serviceA = new InteralService(this.config); // only makes use of  properties a & c in the config
this.serviceB = new OtherInteralService(this.config); // only makes use of  properties b & d in the config
this.serviceC = new YetAnotherInteralService(this.config); // // only makes use of  properties c & f in the config


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source