@ava/babel-plugin-throws-helper

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

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
30Aug 11, 2019Apr 8, 2016Minified + gzip package size for @ava/babel-plugin-throws-helper in KB

Readme

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

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.