Skip to content

Test with toNever(equal(<non nil value>)) fails on encountering nil #1123

@jeslyvarghese

Description

@jeslyvarghese
  • I have read CONTRIBUTING and have done my best to follow them.

What did you do?

Consider the following unit test

func test_toNever_failingOnNil() async throws {
    var sut: String? = "foo"
    Task {
        sut =  nil
    }
    await expect(sut).toNever(equal("bar"))
}

What did you expect to happen?

The test to pass since the expectation set to never be equal to bar is true. Here my intent is to test for value to never equate to 'bar', it becoming nil is also a valid expectation.

What actually happened instead?

Test fails with

expected to never equal <bar>, got <nil> (use beNil() to match nils)

If I follow the suggestion from error message, I will greatly alter the intent of the test.

Environment

List the software versions you're using:

  • Nimble: 13.2.1
  • Xcode Version: 15.2 (15C500b)
  • Swift Version: 5.9.2

Please also mention which package manager you used and its version. Delete the
other package managers in this list:

  • Swift Package Manager: 5.9.0

Project that demonstrates the issue

NimbleIssueDemo.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions