【问题标题】:How to write a test for an http get request in elm如何在 elm 中为 http get 请求编写测试
【发布时间】:2020-10-12 13:49:19
【问题描述】:

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

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

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)

【问题讨论】:

    标签: elm


    【解决方案1】:

    看看https://package.elm-lang.org/packages/avh4/elm-program-test/latest/ProgramTest。来自包装说明:

    此模块允许您通过模拟与您的程序进行交互 用户交互和外部事件(如 HTTP 响应和端口), 并对它呈现的 HTML 和外部的 HTML 做出断言 请求它。

    【讨论】:

      猜你喜欢
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 2017-09-03
      • 2019-08-10
      • 1970-01-01
      • 2016-05-27
      • 2021-01-25
      • 1970-01-01
      相关资源
      最近更新 更多