Skip to content

Test that only decodes. #7

@scott-fleischman

Description

@scott-fleischman

It may be useful for backward-compatibility or forward-compatibility to just test whether you can successfully decode JSON, without trying to test the matching encoding.

Example:

  AesonSpec_Jest.test ("alarmState missing person: ") (fun () ->
    let json = Js.Json.parseExn (Node.Fs.readFileAsUtf8Sync "alarm-golden/AlarmState_MissingPerson.json") in
    let _ = Aeson.Decode.list (fun a -> Aeson.Decode.unwrapResult (OnpingFrontendTypes.decodeAlarmState a)) json
    in AesonSpec_Jest.Ok
  )

This example assumes there is a list of inner decoders we really want to test. But it might be worth considering only making the function test the exact decoding shape and if you call it you can wrap i t in Aeson.Decode.list yourself. We could also provide a couple common decoding functions, one as a list and one as a sample (much like the current functions, but those aren't framed as a test).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions