在 Deno 的 assertThrowsAsync() 中,找到标准异常类型以测试特定异常

In Deno's assertThrowsAsync(), where are standard exception types found to test for specific exceptions

在以下 Deno 测试片段中:

    await assertThrowsAsync(
      async (): Promise<void> => {
        for await (const entry of walk('./non-existent-directory')) {
          console.log(entry)
        }
      },
      NotFound,
      'No such file or directory'
    )

Deno 将类型和消息拼写到控制台 NotFound: No such file or directory (os error 2)

但是 NotFound 异常声明在哪里?当我 运行 使用 deno 1.0.5's standard testing library 剪断时,我得到 error: TS2304 [ERROR]: Cannot find name 'NotFound'.

可以通过 Deno.errors.

访问 Deno 特定错误

对于 NotFound 你应该使用:

await assertThrowsAsync(
  async (): Promise<void> => {
    for await (const entry of walk('./non-existent-directory')) {
      console.log(entry)
    }
  },
  Deno.errors.NotFound,
  'No such file or directory'
)

完整列表如下:

Deno.errors.NotFound
Deno.errors.PermissionDenied
Deno.errors.ConnectionRefused
Deno.errors.ConnectionReset
Deno.errors.ConnectionAborted
Deno.errors.NotConnected
Deno.errors.AddrInUse
Deno.errors.AddrNotAvailable
Deno.errors.BrokenPipe
Deno.errors.AlreadyExists
Deno.errors.InvalidData
Deno.errors.TimedOut
Deno.errors.Interrupted
Deno.errors.WriteZero
Deno.errors.UnexpectedEof
Deno.errors.BadResource
Deno.errors.Http
Deno.errors.Busy