如何在 elm 中为 http get 请求编写测试

How to write a test for an http get request in elm

我正在尝试检查发送请求后收到的数据,为此我需要编写一个测试来确保这一点。

这是处理数据的三个函数。

fetchConfigs : Cmd Msg
fetchConfigs =
Http.get
  { url = "http://localhost:8080/api/sso/configs"
    , expect = Http.expectJson GotConfigs responseDecoder
  }


responseDecoder : Decoder Config
responseDecoder =
    map2 Config
        (field "identifier" string)
        (field "ssoType" int)

type Msg
    = GotConfigs (Result Http.Error Config)

看看https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest。来自包裹描述:

This module allows you to interact with your program by simulating user interactions and external events (like HTTP responses and ports), and making assertions about the HTML it renders and the external requests it makes.