Skip to content

Is there any reason why class defined in a module can't be subsclassed in Pester testcase? #1920

Answered by plastikfan
plastikfan asked this question in Q&A
Discussion options

You must be logged in to vote

@fflaten, thanks for your response. You have confirmed what I feared and I'll just have to accept including a test class in my module. I tried you solution and although referencing the class from inside of the same BeforeAll block does actually work:

  BeforeAll {
    Get-Module Elizium.Loopz | Remove-Module
    Import-Module .\Output\Elizium.Loopz\Elizium.Loopz.psm1 `
      -ErrorAction 'stop' -DisableNameChecking;

    InModuleScope -ModuleName Elizium.Loopz {

      . ([ScriptBlock]::Create('
    class TestGit : SourceControl {
        [string] SomeEcho ($message) {
            return "hello {0}" -f $message
        }
    }'));

      [TestGit]::new(); # => this class reference works ok

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@nohwnd
Comment options

@fflaten
Comment options

Comment options

You must be logged in to vote
5 replies
@fflaten
Comment options

@fflaten
Comment options

@plastikfan
Comment options

@plastikfan
Comment options

@fflaten
Comment options

Answer selected by plastikfan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants