Skip to content

Add IsNotType assertion #1730

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

bartventer
Copy link

This commit introduces the IsNotType assertion, which is the inverse of the existing IsType assertion. It allows users to assert that an object is not of a specific type.

Additionally, minor documentation improvements were made.

Summary

This PR adds a new assertion function, IsNotType, to the testify/assert package. It complements the existing IsType function by providing a way to assert that an object is not of a specific type.

Changes

  • Added the IsNotType function to the assert package.
  • Wrote unit tests for IsNotType to ensure correctness.
  • Updated documentation to include examples and usage for IsNotType.

Motivation

The testify/assert package already provides an IsType function to check if an object is of a specific type. However, there was no built-in way to assert that an object is not of a specific type. This PR addresses that gap by introducing the IsNotType function, improving the library's completeness and usability.

Example usage

assert.IsNotType(t, &MyStruct{}, actualObject)

Related issues

N/A

This commit introduces the `IsNotType` assertion, which is the inverse of the existing `IsType` assertion. It allows users to assert that an object is not of a specific type.

Additionally, minor documentation improvements were made.
Copy link
Collaborator

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds legitimate. I face the need this week too.

Please fix the small typos

This commit fixes a typo in the IsType source file, which caused incorrect behavior in the generated files for the `assert` and `require` packages.
This commit updates the generated files in the `assert` and `require` packages to reflect the changes made in the source file for `IsType`.
@bartventer
Copy link
Author

I have addressed all the requested changes:

  • Fixed the typo in the source file.
  • Regenerated the rest of the files which reflect the corrections.

Let me know if there's anything else you'd like me to adjust.

Simplified the failure message in `IsNotType` to avoid redundancy and improve clarity.
Copy link
Collaborator

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants