Is there documentation on how expect works? As I understand it, it's a keyword you write within a function that tests a condition when that function is executed? If yes, can I write unit tests with it by adding top level functions that only contain expect
?
you can write top-level expects
Hi all! I have a question about using expect
to create a basic test suite for a Roc library.
Essentially: Is there a way to import modules/functions _only_ for use inside expect
?
In this case I'm extracting the Base64 example from the main Roc repo, and I want to write a bunch of tests to make sure it works well.
These mostly have the form of
input |> Encode.toStr |> Decode.fromStr == input
But my problem is that I don't always want to depend on the Decode
module in the Encode
module and vice-versa. (Which is not even possible because of cyclic dependencies), but only for the expect
s.
How to approach this? Move the expect
s to a third module that is not exposed from the library called MyLib.Test
maybe?
Yeah I think I'd make test module in this situation
How do you set up the test module as part of a package? I tried changing
package "Base64"
exposes [
Base64,
Base64.Encode,
Base64.Decode,
]
packages {}
to
package "Base64"
exposes [
Base64,
Base64.Encode,
Base64.Decode,
]
imports [
Test
]
packages {}
But that does not compile.
Moving it to Base64.Test
and creating a Base64.roc
module which contains only
interface Base64
exposes []
imports [Base64.Test]
does sort of work (the expectation is found), but gives an unused module warning
interesting! I think we should have a nicer solution for this (which will require some design work) but in the meantime a workaround is to have Base64.Test expose something useless (like Tests := []
) and then have Base64
do something like _tests : Base64.Test.Tests
- I'm on my phone, but I think that should address the unused warning
Last updated: Jul 06 2025 at 12:14 UTC