Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
    }
like image 945
Adam Labi Avatar asked Jul 11 '26 19:07

Adam Labi


1 Answers

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.

like image 116
Clijsters Avatar answered Jul 14 '26 10:07

Clijsters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!