3.4.0
Introducing the t.try()
assertion
The new t.try()
allows you to try assertions without causing the test to fail:
test('do the thing', async t => {
const attempt = () => t.try(async tt => {
const result = await getResult()
// getResult() can be flaky and sometimes throws :(
tt.is(result, 'expected')
})
const firstAttempt = await attempt()
if (firstAttempt.passed) return firstAttempt.commit()
t.log('Retrying (just once)')
firstAttempt.discard()
const secondAttempt = await attempt()
secondAttempt.commit()
})
You can use any test implementation with t.try()
, including (arrays of) macros. You can decide what to do with attempts. You can even run attempts concurrently, so long as they don't use snapshot assertions.
This is great building block for handling all kinds of advanced test scenarios. We can't wait to see what you'll do with it! Find out more in the assertion documentation.
This feature was previously behind an experimental flag. That flag has now been removed. If you have enabled the flag you'll have to update your AVA config. Also note that as of this release, attempt titles are always prefixed with the title of the parent test 7ee3a0e.
Once again, thank you @qlonik for contributing this new assertion.
In case you missed it: ESM support
As of the 3.3.0 release, AVA can load ESM test files! Check our updated ES Modules recipe for details.
Our ESM support is still incomplete. Progress is tracked in the ESM support project. Join us, won't you?
Other changes
- The
t.throws()
andt.throwsAsync()
assertions can now be called withundefined
as the second argument. Previously, if you wanted to set an assertion message but did not want to provide any expectations for the thrown error you had to passnull
. That's still allowed, of course. d0e2161 @stavalfi ava.config.js
files once again work with our@ava/typescript
package f4d4edd- Our TypeScript definition no longer references
@types/node
7a1dacf - We've improved the error message shown when
test.cb()
is used with asynchronous functions or observables f5a8c2b @toddkcarlson - The Vue recipe has been updated to use
jsdom-global
instead ofbrowser-env
3f9c616 @Scrum - @fisker optimized how we detect ESM support 8831f54
See v3.3.0...v3.4.0 for all changes.