[UNIT TESTING - with Jest] Hi folks, is there an...
# typescript
m
[UNIT TESTING - with Jest] Hi folks, is there any way to mock functions like
pulumi.getOrganization()
or
pulumi.getStack()
for unit tests? we use them internally from some constructs to avoid passing those values as inputs through the whole hierarchy of classes and unit tests always fail with
Missing organization name; for test mode, please call 'pulumi.runtime.setMocks'
despite that setMocks is properly called at the beginning of all tests
v
Hi! This is an example from one of our projects where we mock in some Jest unit tests. The first parameter specifies the behavior, and the following parameters will mock the organization, project and stack values. Haven't tested this with getStack() etc, but in theory it should I would think
image.png
m
thanks for replying! we already have setup those too, but as soon as we have
pulumi.getOrganization()
in a file that is imported directly or indirectly in a unit test, it throws the error
k
Hi! I managed to get this working. There's a 5th parameter for the organization. Essentially we've been using it wrong, so sorry about that. This one returned the expected result though!