How do I Mock [System.IO.Path]::IsPathRooted() using Pester? I tried the following but no luck.
Describe "Configuration" {
Mock [System.IO.Path]::IsPathRooted {
return false
}
It "should mock rooted Path" {
[System.IO.Path]::IsPathRooted("C:\a") | Should Be False
}
Unfortunately the answer to your question is short and simple:
You can't.
According to Pester's Github Issue #72, the best alternative is to wrap the method call in a separate function and Mock this function.
There are a few discussions about this and a lot of people would love to be able to mock .Net methods, but until now, I was unable to find any solution on this. Unfortunately, even overwriting methods (independent of Pester) isn't that easy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With