The documentation for <data-driven-testing> fails ...
# kotest
m
The documentation for data-driven-testing fails to mention that
withData()
is only available in a container scope, so If a user tries to experiment using a
StringSpec
, they will be met with a compilation error and left puzzled, as it just happened to me 😄
s
Once we get to Kotest 6, StringSpec will be deprecated as FreeSpec will do it all.
StringSpec will stay as an alias to FreeSpec
m
Ok good to know. But I think the documentation problem will remain. Even using FreeSpec I can write this:
Copy code
class DataDrivenTest : FreeSpec({
    "parametric test" {
        withData(/*values*/) { ... ->
            // test code
        }
    }
})
now the class compiles but I get a runtime error:
Cannot add a root test after the spec has been instantiated:
which isn't very clear to be honest. Still, the docs fail to explain that you need to be inside a container scope to use withData(). And this applies to all the styles, that have both container and terminal scopes. Yes, the provided example shows that FunSpec's
context()
is used, but I believe it may not be immediately evident for library users, especially when starting out, and it should be explained in the docs.
s
I'll clarify the docs when I have a chance
m
Thank you, just wanted to let you know, to benefit all library users. I love Kotest, thanks for your outstanding work!
s
Thank you 🙂
m
well, no sh*t... 🙂 I should really thank that monkey for providing a solution! The point here is not that I didn't know how to fix it, but the documentation not being clear about where
withData()
can be used. Luckily the documentation has been amended now.
h
The documentation still isn't clear enough, at least not for a monkey like me 🙈
Also this monkey didn't realize that I posted your own answer to you 😄
m
I agree that talking only about container or leaf scopes without any prior example is not very clear
h
Just tried to spread the joy when finally figured this out blob joy
m
that I posted your own answer to you
yeah, that was my joke, as a monkey
h
we are all monkeys
this monkey clearly needs more coffee, though (or less)
m
⬅️ I'm definitely more than others, look at my propic
awkward monkey 1
128 Views