It'd be really nice if you could mark a dependency as optional by specifying a default value for it like so:
jpex.factory<Foo>((bar: Bar = defaultBar) => () => {});
jpex.resolve<Foo>(); // Uses default bar
This would mean if you didn't ever register a Bar factory, you could still resolve Foo and it would use defaultBar instead of throwing an error.
You could then specify dependencies but rather than having to manually create factories for them all, you could use the default value, but inject a custom dependency under test, for example.
// Some test
const stubbedBar = () => {};
jpex.constant<Bar>(stubbedBar);
jpex.resolve<Foo>(); // Uses stubbed bar
It'd be really nice if you could mark a dependency as optional by specifying a default value for it like so:
This would mean if you didn't ever register a
Barfactory, you could still resolveFooand it would usedefaultBarinstead of throwing an error.You could then specify dependencies but rather than having to manually create factories for them all, you could use the default value, but inject a custom dependency under test, for example.