Skip to content
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

add .contains() support to expectThrows{} #297

Open
kenyee opened this issue Sep 28, 2023 · 3 comments
Open

add .contains() support to expectThrows{} #297

kenyee opened this issue Sep 28, 2023 · 3 comments

Comments

@kenyee
Copy link

kenyee commented Sep 28, 2023

Sometimes you want to compare that the exception message is what you expect.

I currently use a combo of assertThrows like this:

val exception = assertThrows {}
expectThat(exception.message!!).contains("somestring")

because expectThrows doesn't let me check the message..

@AlexanderGH
Copy link

This works for me in the current version:

expectThrows<Throwable> { }.get { message }.isNotNull().contains("somestring")

as does:

expectThrows<Throwable> { }.assert("message") {
    expectThat(it.message).isNotNull().contains("somestring")
}

@kenyee
Copy link
Author

kenyee commented Nov 21, 2023

Thanks! That did work out well. An example probably should be added to the docs.
expectThrows { }.message().isNotNull().contains("...")
would be slightly nicer...

@AlexanderGH
Copy link

You could add an extension method that aliases message() to get { message }.

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

No branches or pull requests

2 participants