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
BeOfType doesn't see types, loaded from a file with classes, but the "It" function - does #2414
Comments
Thanks for the report. TLDR: Using Try Long version 🙂 By dot-sourcing # Run in child scope similar to your test file. Class is not available when the script is finished -> child scope with class imported is deleted
> & ./Classes.ps1; [MyTestClass]
InvalidOperation: Unable to find type [MyTestClass]. The typical solution would be to place the class in a module like Unfortunately working with classes in PowerShell has lots of weird behavior like this. A few workarounds:
|
Keep open until we've updated docs and function help with an example that passes the type-object properly (with parentheses). Maybe also be clean up own internal tests, besides https://github.com/pester/Pester/blob/main/tst/functions/assertions/BeOfType.Tests.ps1 which is already good. |
Thank you @fflaten for this explanation! |
Checklist
What is the issue?
I have a .ps1 files containing definitions of my classes. I load that file in a
BeforeAll
block. Later in my tests I can successfully create objects using these classes, but theShould-BeOfType
function does not see those types even so theIt
function - does.Running the test defined below, I receive the following output:
When executing the test step-by-step, I see that my class is indeed not available in the scope of the
Should-BeOfType
function.Expected Behavior
Types available in an
It
block are available to use with theShould -BeOfType
command. The test defined below should pass successfully.Steps To Reproduce
where Classes.ps1 is:
Describe your environment
Possible Solution?
No response
The text was updated successfully, but these errors were encountered: