Automated unit tests or folding Array Unit to Unit [SOLVED]

Hi everybody! For my unit tests I wanted to read a json file with all test cases and run them with something like

runTestCase tc =
  test "a check" do
    Assert.equal tc.request.body tc.response.body

main :: Effect Unit
main =
  launchAff_ do
    rs <- readOrThrow "./test/Server/testCases.json"
    ts <- mkTestCase "./test/Server" `traverse` rs
    runTestWith runTest do
      suite "Tests" do
        runTestCase `traverse` ts

The error is Could not match type Array Unit with type Unit.
Does somebody know how to resolve this?

It would be great if you could show us the full code (e.g. how are mkTestCase and runTestCase defined?) and full error too.

I’m pretty sure the issue is with your last line. runTestCase looks like TestCase -> Effect Unit, and ts looks like an Array TestCase, so when you call traverse, you end up with an Effect (Array Unit). You can only put an effect on a line by itself without binding it to a name if it’s type is Effect Unit. So to resolve it, you could either do

_ <- runTestCase `traverse` ts
pure unit

or just

runTestCase `traverse_` ts
1 Like

Yeah, that’s it. Thanks! I was the whole time looking for some kind of unit concat. :roll_eyes:

1 Like