Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Assert-MockCalled is not compatible with Aliases

Open vicp-iq opened this issue 10 years ago • 6 comments

I have some code that looks like this:

InModuleScope MyModule {
    Describe "My Class" {
        Mock Select-AzureRmSubscription {}
        Context 'when calling My Method' {
            It 'does a thing' {
                Assert-MockCalled Select-AzureRmSubscription
            }
    }
}

I get the following error:

Describing MyModule
  Context when calling My Method
    [-]does a thing 40ms
      RuntimeException: You did not declare a mock of the Select-AzureRmSubscription Command in module MyModule.

My digging revealed that if I had called Assert-MockCalled Set-AzureRmContext instead, that would have worked

vicp-iq avatar Dec 08 '15 20:12 vicp-iq

Ah, good point. Mock resolves aliases to their actual command names, but Assert-MockCalled is not currently doing that. Will fix shortly, thanks!

dlwyatt avatar Dec 08 '15 20:12 dlwyatt

Awesome, thanks!

vicp-iq avatar Dec 08 '15 20:12 vicp-iq

Fixed in commit 2e2a9c37. I pushed straight to master instead of doing a PR.

dlwyatt avatar Dec 08 '15 22:12 dlwyatt

Awesome, thanks! Do you know when the next version of Pester will be published, so I can get this fix through "Update-Module"?

vicp-iq avatar Dec 08 '15 22:12 vicp-iq

Probably tonight. We've got quite a bit of unreleased stuff in the master branch now, so it's just about time for another publish.

dlwyatt avatar Dec 08 '15 22:12 dlwyatt

Done, 3.3.12 is published.

dlwyatt avatar Dec 08 '15 23:12 dlwyatt