如何用笑话测试 TaskEither 形式的 fp-ts

How to test TaskEither form fp-ts with jest

我是 fp-ts 的新手。假设我有一个读取和解析配置的函数 (path: string) => TaskEither<Erorr, T>,我想为此编写一个测试。

到目前为止我有:

test('Read config', done => {
  interface Config {
    fld1: string
    fld2: {
      fld: 3
    }
  }

  pipe(
    readConfig<Config>("resources/test-config.toml"),
    TE.fold(
      err => T.of(done(err)),
      toml => T.of(() => {
        expect(toml).toBe({})
        done()
      })
    )
  )

})

但超时失败。而且我不确定我是否正确实施了折叠。一般如何将TaskEither折叠成Task然后异步调用?

我缺少函数调用。

应该是:

  pipe(
    readConfig<Config>("resources/test-config.toml"),
    TE.fold(
      err => T.of(done(err)),
      toml => T.of(() => {
        expect(toml).toBe({})
        done()
      })
    )
  )()