@@ -84,22 +84,23 @@ Describe 'PSModule - Module tests' {
8484 }
8585 }
8686
87- Context ' Framework - Module OnRemove cleanup' {
88- It ' Should remove the module cleanly and re-import without errors' {
87+ Context ' Framework - Module OnRemove cleanup' - Skip:(-not $hasClassExporter ) {
88+ It ' Should clean up type accelerators when the module is removed' {
89+ # Capture type names before removal
90+ $typeNames = @ (@ ($expectedEnumNames ) + @ ($expectedClassNames ) | Where-Object { $_ })
91+ $typeNames | Should -Not - BeNullOrEmpty - Because ' there should be types to verify cleanup for'
92+
8993 # Remove the module to trigger the OnRemove hook
90- { Remove-Module - Name $moduleName - Force } | Should -Not - Throw
94+ Remove-Module - Name $moduleName - Force
9195
92- # Verify type accelerators are cleaned up when class exporter is present
93- if ($hasClassExporter ) {
94- $typeNames = @ (@ ($expectedEnumNames ) + @ ($expectedClassNames ) | Where-Object { $_ })
95- $typeAccelerators = [psobject ].Assembly.GetType(' System.Management.Automation.TypeAccelerators' )::Get
96- foreach ($typeName in $typeNames ) {
97- $typeAccelerators.Keys | Should -Not - Contain $typeName - Because " the OnRemove hook should remove type accelerator [$typeName ]"
98- }
96+ # Verify type accelerators are cleaned up
97+ $typeAccelerators = [psobject ].Assembly.GetType(' System.Management.Automation.TypeAccelerators' )::Get
98+ foreach ($typeName in $typeNames ) {
99+ $typeAccelerators.Keys | Should -Not - Contain $typeName - Because " the OnRemove hook should remove type accelerator [$typeName ]"
99100 }
100101
101102 # Re-import the module for any subsequent tests
102- { Import-Module - Name $moduleName - Force } | Should -Not - Throw
103+ Import-Module - Name $moduleName - Force
103104 }
104105 }
105106}
0 commit comments