Skip to content

Should-BeString should allow empty strings for the -Expected parameter #2857

Description

@CedX

Checklist

I've this kind of v5 test:

It "should do something" -ForEach @(
	@{ Value = ""; Length = 0; Expected = "" }
	@{ Value = "foo bar"; Length = 3; Expected = "foo" }
) {
	Format-String $value -Truncate -Length $length | Should -BeExactly $expected
}

When porting it to v6, I now must use:

It "should do something" -ForEach @(
	@{ Value = ""; Length = 0; Expected = "" }
	@{ Value = "foo bar"; Length = 3; Expected = "foo" }
) {
	$actual = Format-String $value -Truncate -Length $length
	if ($expected) { Should-BeString $expected $actual -CaseSensitive }
	else { Should-BeEmptyString $actual }
}

I would have preferred not to have to use two different assertions depending on whether the expected value is an empty string or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions