expekt icon indicating copy to clipboard operation
expekt copied to clipboard

Add exception expectation.

Open saku opened this issue 8 years ago • 3 comments

  • It can use Closure and test exception.
  • raise check exception type strictly.
    • It will fail when Closure does not throw expected exception.
  • raiseAny check exception type not strictly.
    • It will fail when Closure does not throw any exception.

Example

passes
expect({ throw NullPointerException() }).raise(NullPointerException::class)
expect({ throw NullPointerException() }).raiseAny()

fails
expect({ /* nothing to thrown */ }).raise(NullPointerException::class)
expect({ throw CustomException() }).raise(NullPointerException::class)

#2

saku avatar Dec 17 '16 08:12 saku

+1

VerachadW avatar Dec 29 '16 10:12 VerachadW

+1

lucasluiz avatar May 18 '17 16:05 lucasluiz

👍

joshskeen avatar Jun 21 '18 19:06 joshskeen