I wan't to get a resource from my yesod app and assert it matches a known JSON value.
I can see that in Yesod.Test.Json
there is the function assertJSON
with the type
assertJSON :: (ToJSON a, FromJSON a) => (a -> (String, Bool)) -> SResponse -> Session ()
But there is no example usage and I can't work out how this is used from the type alone.
How would I be able to check that the JSON returned from my yesod app matches?
It looks to me like you acquire an
SResponse
in aSession
do block as per https://hackage.haskell.org/package/wai-test-0.1.1/docs/Network-Wai-Test.html (googledSResponse
and checked that the module matched one imported by https://hackage.haskell.org/package/yesod-test-json-0.2.0.0/docs/src/Yesod-Test-Json.html), choose a typea
that you want to assert the JSON to encode, construct a functiona -> (String, Bool)
whose second argument specifies whether your desired property holds and whose first argument specifies the error to output otherwise (should have beena -> Either String Bool
imo) (checked the source), then applyassertJSON
to the function and theSResponse
within that same do block to express the assertion.