0.19.0
Since our last minor release, @novemberborn has worked tirelessly on refactoring big parts of the codebase to be more correct and readable, while squashing many bugs. We've also added multiple detections that will prevent user mistakes.
Highlights
Working snapshots
We released snapshot support with v0.18.0
, but unfortunately it didn’t work. That’s fixed now. Since we’re using jest-snapshot
the output will look a little different from AVA’s other assertions. Most notably the output will not be colored.
Tests fail if no assertions are run (BREAKING)
Sometimes you write a test that accidentally passes, because your assertion was never run. For example, the following test passes if getAnimals()
returns an empty array:
test('unicorn', t => {
for (const animal of getAnimals()) {
t.is(animal, 'unicorn');
}
});
AVA now fails your test if no assertions were run. This can be a problem if you use third-party assertion libraries, since AVA cannot detect when those assertions pass. You can disable this behavior by setting the failWithoutAssertions
option to false
in AVA's package.json
configuration.
Improved t.throws()
and t.notThrows()
assertions (BREAKING)
Various improvements have been made to these assertions. Unfortunately this does include some breaking changes.
Calling these assertions with an observable or promise makes them asynchronous. You now need to await
them:
const promise = Promise.reject(new TypeError('🦄'));
test('rejects', async t => {
await t.throws(promise);
});
Previously, these would return a promise that was rejected if the assertion failed. This leaked AVA’s internal assertion error. Now they’ll fulfill their returned promise with undefined
instead (d56db75). You typically won’t notice this in your test.
We’ve improved how we detect when t.throws()
and t.notThrows()
are used incorrectly (d924045). This might be when, rather than passing a function, you call it:
test('throws', t => {
t.throws(throwingFunction());
});
You can now use await
and yield
in the argument expressions (e.g. t.throws(await createThrowingFunction())
. The instructions on how to use these assertions correctly are now shown with the test failure, instead of being written to the console as your tests run.
Incorrectly using these assertions now always causes your test to fail.
Stack traces are now correct, even if used asynchronously (f6a42ba). The error messages have been improved for when t.throws()
fails to encounter an error, or if t.notThrows()
does (4463f38). If t.notThrows()
fails, the encountered error is shown (22c93ed).
Improved magic assert output
Actual and/or expected values are now included in the magic assert output, with helpful labels that are relevant to the failing assertion.
Detect hanging tests
AVA can now detect when an asynchronous test is hanging (880e87e).
Note that this may not work if your code is listening on a socket or is using a timer or interval.
Better Babel option resolution
We’re now resolving Babel options ahead of time, using hullabaloo-config-manager
. This fixes long-standing issues with relative paths in AVA’s "babel"
options in package.json
files (#707). It also means we’re better at recompiling test and helper files if your Babel config changes or you update plugins or presets.
Miscellaneous
- There is a new recipe for precompiling source files with webpack. a49f66b
- You can now type the test context when using TypeScript. 50ad213
- The color of text diff output has been fixed. 9f2ff09
- Text diffs are now faster. bd5ed60
- Values are no longer highlighted if colors are disabled. b581983
- AVA no longer crashes if tests fail with non-errors. 157ef25
- YAML blocks in the TAP output have been improved. 3279336
- We’re now printing assertion statements with less depth. 0510d80
- Arguments to
t.regex()
andt.notRegex()
are now validated. f062981
All changes
Thanks
💖 Huge thanks to @Wp1987, @lukechilds, @jakwuh, @danny-andrews, @mmkal, @yatharthk, @klauscfhq, @screendriver, @jhnns, @danez and @florianb for helping us with this release. We couldn’t have done it without you!
Get involved
We welcome new contributors. AVA is a friendly place to get started in open source. We have a great article on getting started contributing and a comprehensive contributing guide.