-
Hi all (I've posted the same question in Powershell forums but on a second thought, here is probably the best place to ask) I’m assigned to write a bunch of tests on an existing codebase and a number of my tests hang. The code, simplified to show the issue, is as follows: File MySharepointModule.ps1 :
File MyScript.ps1 :
In order to avoid setting up a Sharepoint site, I’m mocking Set-PnPListItem.
It works for the first call. But on the second call, where it’s being called from the module, Set-PnPListItem hangs. It doesn’t even throw an error -just hangs. And if I need to run the tests again, I have to kill the terminal or restart VSCode. I’ve tried different variations, even leaving the mock empty. Nothing works, it always hangs. The only way I can get it to work is if I mock Update-SharepointList itself, but that means leaving this code untested. Is this a known issue, behaviour or bug? Are there any workarounds? Many thanks in advance Jim |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi. This is by design. The mock isn't called when invoked through You need two mocks for you sample.
Try adding: Mock Set-PnPListItem -ModuleName MySharepointModule {
# store args into a variable
} |
Beta Was this translation helpful? Give feedback.
Hi. This is by design. The mock isn't called when invoked through
Update-SharepointList
as it invokes from another state (the module).You need two mocks for you sample.
Try adding:
See https://pester.dev/docs/usage/modules