Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should Throw - need to expose error details #58

Closed
staxmanade opened this issue Jul 3, 2013 · 2 comments
Closed

Should Throw - need to expose error details #58

staxmanade opened this issue Jul 3, 2013 · 2 comments

Comments

@staxmanade
Copy link
Contributor

Given the following test

It "should not fail" {
    { throw 'helpful error message' } | Should Not Throw
}

I get the following output.

[-]   should fail 2ms
      Expected: the expression to not throw an exception
      at line: 9 in C:\Code\sample\powershellTests\src\run-sample.Tests.ps1

When an exception happens in a test, I would be helpful if we could see the actual exception. Currently the exception information appears to be swallowed and is hiding crucial details that would help us diagnose a failing test.

Similarly if we say "{ something } | Should Throw" I would be great if you could consider a syntax that would allow us to assert more specific information about the error.

Possibly something like

{ throw "hi"; } | Should Throw "hi"

Keeping in mind wild card or regex searches

{ [string]::Format("{0} {1}", "hello") } | Should Throw "*Index (zero based) must be greater than or equal to zero and less than the size of the argument list.*"

Or be able to determine the type of the exception object.

@FallenGameR
Copy link

Actually Pester also discards error info and makes it impossible to get the error details right now:

    It "does not record error information for tests" `
    {
        $error.Count | should be 0
        {throw "anything"} | should throw
        $error.Count | should be 0
    }

@jole78
Copy link
Contributor

jole78 commented Sep 2, 2013

This would be a huge improvement. I often find myself wanting to test for the actual exception message and not only for a thrown exception.

edharper01 added a commit to edharper01/Pester that referenced this issue Oct 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants