You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix GetType() bad pattern and related issues in tests (PowerShell#3134)
* Fix GetType() bad pattern and related issues in tests
$var.GetType() can raise an exception in tests so we should check $var
before make the call. A large part of the tests does not make this
check.
I start with searching ".GetType()" but discovered many related issues
in tests (reduntant and unneeded tests, "throw" bad pattens, bugs,
formattings (sorry!) and so on) - I had to fix them too.
* Fix after code review
* Second wave of migration GetType() -> BeOfType
Removed 'GetType().Name' patterns.
Copy file name to clipboardExpand all lines: test/powershell/Language/Scripting/ActionPreference.Tests.ps1
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -19,9 +19,9 @@
19
19
20
20
It '$err.Count' { $err.Count| Should Be 1 }
21
21
It '$err[0] should not be $null' { $err[0] | Should Not Be $null }
22
-
It '$err[0].GetType().Name' { $err[0].GetType().Name| Should Be ActionPreferenceStopException }
22
+
It '$err[0].GetType().Name' { $err[0] | Should BeOfType "System.Management.Automation.ActionPreferenceStopException" }
23
23
It '$err[0].ErrorRecord' { $err[0].ErrorRecord | Should not BeNullOrEmpty }
24
-
It '$err[0].ErrorRecord.Exception.GetType().Name' { $err[0].ErrorRecord.Exception.GetType().Name| Should Be ItemNotFoundException }
24
+
It '$err[0].ErrorRecord.Exception.GetType().Name' { $err[0].ErrorRecord.Exception | Should BeOfType "System.Management.Automation.ItemNotFoundException" }
0 commit comments