@ava/babel-plugin-throws-helper

中文文档
4.0.0发布于 2019/08/12MIT零依赖近 30 天下载 23.9万

Babel plugin for protecting against improper use of t.throws() in AVA

原始使用文档
文档目录3 节
  1. Issue
  2. Solution
  3. License

babel-plugin-throws-helper Build Status

Babel plugin for protecting against improper use of t.throws() in AVA

Probably not useful except as an internal plugin for the AVA test runner.

Genesis of the idea.

Issue

I've seen a lot of incorrect use of the throws assertion in other test runner and even done the mistake myself sometimes. Now I'm beginning to see it with AVA too, so would be nice to be preemptive about it.

People don't realize they need to wrap their call in a function, so many end up doing t.throws(foo()) instead of t.throws(() => foo());. It's an easy mistake to make.

The difficulty is that t.throws(foo()) is allowed if foo() returns a promise or a function. There is no good way to differentiate between the two at runtime. So providing a good error message is going to take some AST transform magic.

Solution

See test.js.md for the transformation this plugin performs.

License

MIT © James Talmage

版本与发布记录

@ava/babel-plugin-throws-helper 共发布 11 个版本,首次发布于 2017/03/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.0latest2019/08/127 年前
3.0.02018/08/298 年前
3.0.0-beta.82018/08/128 年前
3.0.0-beta.72018/06/138 年前
3.0.0-beta.62018/05/308 年前
3.0.0-beta.52018/05/258 年前

关于 @ava/babel-plugin-throws-helper 的常见问题

@ava/babel-plugin-throws-helper 是什么?

Babel plugin for protecting against improper use of t.throws() in AVA

如何安装 @ava/babel-plugin-throws-helper?

在项目目录运行 npm install @ava/babel-plugin-throws-helper,或使用 pnpm add / yarn add / bun add。

@ava/babel-plugin-throws-helper 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/ava__babel-plugin-throws-helper 是否存在。

@ava/babel-plugin-throws-helper 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ava/babel-plugin-throws-helper 可以商用吗?

@ava/babel-plugin-throws-helper 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ava/babel-plugin-throws-helper 的下载量有多少?

根据 npm 官方下载统计,@ava/babel-plugin-throws-helper 在 2026/10/07 – 2026/11/05 这 30 天内被下载 239,413 次,日均约 7,980 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ava/babel-plugin-throws-helper 还在维护吗?

最新版本 4.0.0 发布于 2019/08/12(7 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/03/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。