Mock [System.IO.Path]::IsPathRooted() using Pester? Mock [System.IO.Path]::IsPathRooted() using Pester? powershell powershell

Mock [System.IO.Path]::IsPathRooted() using Pester?


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.