Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Question: Mocking static class

Open VaughanJ opened this issue 5 years ago • 1 comments

Powershell 7 used.

I have a module that uses a lot of classes, some of them are static classes. I'm looking for some documentation on how best to mock these methods in the classes, especially the static classes. Can you point me to anything that might help please?

The closest I find is: https://pester.dev/docs/usage/mocking

Which talks about mocking functions that called by classes.

VaughanJ avatar Sep 28 '20 21:09 VaughanJ

https://gist.github.com/nohwnd/670aa06b989c826c22fab86742a1d6c6 there is only this raw example of how this could be done replacing a method on a static class with Harmony. This is far from finished, but might potentially become a full module. @SeeminglyScience is also doing some research on this. And once I get some time I want to start writing a module around this, which would in the end integrate with (or extend) Pester's Mock.

Wanna help? You can start by showing some examples of what you are trying to do.

nohwnd avatar Sep 29 '20 06:09 nohwnd