Skip to content

Commit c694fad

Browse files
fix: module OnRemove test no longer skips for modules without class exporter
1 parent fffbcdb commit c694fad

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/tests/Module/PSModule/PSModule.Tests.ps1

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,22 @@ Describe 'PSModule - Module tests' {
8484
}
8585
}
8686

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-
87+
Context 'Framework - Module OnRemove cleanup' {
88+
It 'Should remove the module cleanly and re-import without errors' {
9389
# Remove the module to trigger the OnRemove hook
94-
Remove-Module -Name $moduleName -Force
90+
{ Remove-Module -Name $moduleName -Force } | Should -Not -Throw
9591

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]"
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+
}
10099
}
101100

102101
# Re-import the module for any subsequent tests
103-
Import-Module -Name $moduleName -Force
102+
{ Import-Module -Name $moduleName -Force } | Should -Not -Throw
104103
}
105104
}
106105
}

0 commit comments

Comments
 (0)