[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
victorious-musician-62050
01/09/2025, 3:27 PM
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
victorious-musician-62050
01/09/2025, 3:28 PM
image.png
m
mammoth-diamond-90308
01/12/2025, 10:18 AM
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
kind-motherboard-59197
01/12/2025, 11:26 AM
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!
No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.