-
-
Notifications
You must be signed in to change notification settings - Fork 476
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
Feature Request: Expected, Actual, and Because as Test Property Fields #1993
Comments
Sounds good. We already transport some data on the exception (in the data dictionary of the exception), this would be adding more items. We should make sure we save the serialized version of the object, to avoid holding references to the real object. https://github.com/pester/Pester/blob/main/src/functions/assertions/Should.ps1#L17-L18 |
IIRC that function isn't called anymore. It's been converted to a c# method in Pester.Factory. Concept probably still applies though. |
Yeah, the concept should be okay, the data are imho attached to the data dictionary on the exeception which is defined on the Exception base class so any .net exception has it. |
There is some information in targetObject but nothing specific to the error other than the message. I think the most appropriate storage for this is
|
I'd be happy to PR this @nohwnd @JustinGrote. A lot of the This would actually be very useful for the work I'm doing. I am also just parsing the message with regex and being able to access these properties inside the exception would be great. |
Exception is a universal carrier of failure info. You can throw exceptions from your own assertions if you don't want to use Should. That is why I am suggesting to use Data on Exception object. |
6 month follow up :) |
@JustinGrote hello from 4 more months into the future :D Someone needs to just implement this. Maybe you yourself? 😉 |
* Feature Request: Expected, Actual, and Because as Test Property Fields Fixes #1993 * Add lingering "Be" because value * Add missing because argument * Add a strong type to ShouldResult * Fix issue with HaveCount having a typed ExpectedValue parameter * Update src/functions/assertions/Should.ps1 Co-authored-by: Frode Flaten <3436158+fflaten@users.noreply.github.com> * Refactor to guard clauses to ensure success records do not have additional properties * CreateShouldErrorRecord to object type * Add ExpectResult and strong typing to Should -Invoke * Remove null failuremessage --------- Co-authored-by: Frode Flaten <3436158+fflaten@users.noreply.github.com> Co-authored-by: Jakub Jareš <me@jakubjares.com>
@nohwnd thank you! |
Thank you :) |
It is now released in beta if you want to promote or try it further. |
@nohwnd The github release tag + notes are missing this + 3 other commits. The published build is fine. |
I've found only 2 commits missing, the tag was on wrong commit. not sure what other 2 I a missing, maybe those are the two for dropping powershell support and revert of that , which are linked at the bottom of the release notes? |
I think it was the azure-pipelines commits. But all good now, thanks 🙂 |
Yeah I think I made a commit locally into main, and then pulled because there was extra work, but instead of forwarding it merged, and I did not want that, so I reset to the remote state, cherry-pick the changes and push. But before this I've tagged the latest commit, but that commit did not end up on main, because I cherry picked it. And I do recall that I've reapplied the tag, but I probably did it wrong. |
Summary of the feature request
The vscode proposed test UI has a very nice view window showing expected and actual results including a diff
![image](https://user-images.githubusercontent.com/15258962/122003167-916b8380-cd67-11eb-89d0-6497aab81aa3.png)
I would like to be able to display this similar information from Pester, but currently since the error is just a string, it would require a lot of parsing.
How should it work? (optional)
Ideally a failure would add 3 parameters either to the data of the exception or to the testresult itself:
Example with Should -Be:
Expected $false, but got $true
Example with Should -BeOfType:
Expected the value to have type [int] or any of its subtypes, but got $true with type [bool].
Also support Because, which would probably be shown as a comment to Expected
As a workaround a regex parsing of "Expected x, but y" would probably suffice for most scenarios
The text was updated successfully, but these errors were encountered: