Is there a way to break down `test`s into phases/s...
# kotest
k
Is there a way to break down `test`s into phases/steps using some kotest semantics, purely for better readability experience?
Copy code
test("foo") {
  step("do something") {
    // ...
  }

  step("do something else") {
    // ...
  }
}
e
Does
withClue
match what you want?
k
You can also use `FreeSpec`:
Copy code
class MyTest: FreeSpec({
    "foo" - {
        "do something" {
            /...
        }
        "do something else" {
            /...
        }
    }
})
s
Or
BehaviourSpec
with
Given
,
When
,
Then
+ my favorite one:
And
?
👍 1
s
FunSpec allows
Copy code
context("foo") { 
  test("bar") {}
  test("baz") {}
}
k
withClue
is what I was looking for 🙂
👍🏻 1
k
While on the subject of
withClue
, sometimes I wish there was a way to add the text after the assertion instead of having to always put it before. For example, it would be nice if there was an "otherwise" like
<actual> shouldBe <expected> otherwise "<actual> is the wrong value!"
. I think that would read nicer.
s
Funny you say that because there's a ticket someone opened to "fix" it so its before on all assertions.
k
I think that's a different issue (assuming you're referring to https://github.com/kotest/kotest/issues/3694?). I was talking about where the clue appears in the source code, not in the failure message.