Does anyone know the best way to mock the resource...
# typescript
r
Does anyone know the best way to mock the resource to unit test?
l
To fake a resource, Pulumi provides the
pulumi.runtime.setMocks()
function, which allows you to create dumb or smart stubs for all resource constructors and provider getters. Is that what you're looking for?
👍 1
There is no true mocking support, you would have to add that yourself, maybe via a mocking library.
r
I have pretty lengthy stack.yaml and using static variables on a class to get access to the configs, but I think you're right I just need to actually just do the mock myself. Thanks!
l
Generally, configs are best loaded by index.ts, which isn't faked / stubbed. All configuration values, wherever they come from, should be passed into the constructor of a resource.
This helps with lowering coupling and increasing both testability and readability.
❤️ 2
Don't test your use of configuration, just class/component logic.
r
Very helpful thank you