Skip to content

Breaking changes to the test() interface #2785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 10, 2021
Merged

Conversation

novemberborn
Copy link
Member

@novemberborn novemberborn commented Jul 5, 2021

Fixes #2716.

Remove support for passing multiple test implementations. This affects test() and t.try().

Supporting multiple implementations made both the implementation and the type definitions needlessly complex. Using for/of syntax it's easy enough to declare tests (or t.try() attempts) with the same arguments.

Change constructor type for instanceOf expectation. It should result in an Error subclass.

Add test.macro(), change how macros are typed. Fixes #2189. test.macro() returns an object that can be used with
test() and hooks. The t.context type is inherited from test.

Like with AVA 3, regular functions that also have a title property that is a string-returning function are supported. However this is no longer in the type definition.

Instead the recommended approach is to use test.macro() to declare macros. At a TypeScript level these are easier to discriminate from regular implementations.

Change implementation argument type constraint to unknown. This mostly impacts macros, for which we'd want to encourage explicit types.

Add test for context covariance. Fixes #2253 which no longer seems reproducible.

Add test for implementation result types.

Refactor type definition. Split across multiple files. Rename types, most noticeably TestInterface is now TestFn, but really anything that had the Interface suffix has been changed. Update some documentation.

Return null when throws() and throwsAsync() assertions fail.

Update type definitions to disallow null throws expectations.

This affects test() and t.try().

Supporting multiple implementations made both the implementation and the
type definitions needlessly complex. Using for/of syntax it's easy
enough to declare tests (or t.try() attempts) with the same arguments.
Fixes #2189. `test.macro()` returns an object that can be used with
`test()` and hooks. The `t.context` type is inherited from `test`.

Like with AVA 3, regular functions that also have a `title` property
that is a string-returning function are supported. However this is no
longer in the type definition.

Instead the recommended approach is to use `test.macro()` to declare
macros. At a TypeScript level these are easier to discriminate from
regular implementations.
This mostly impacts macros, for which we'd want to encourage explicit types.
Fixes #2253 which no longer seems reproducible.
* Split across multiple files.

* Rename types, most noticeably `TestInterface` is now `TestFn`, but
really anything that had the Interface suffix has been changed.

* Update some documentation.
@novemberborn
Copy link
Member Author

Note that test.macro() isn't compatible with our ESLint plugin: avajs/eslint-plugin-ava#329

Make the behavior explicit in the documentation and type definition.
The implemenation already fails the assertion when null is provided.
@novemberborn novemberborn merged commit b237d33 into main Jul 10, 2021
@novemberborn novemberborn deleted the test-interface-changes branch July 10, 2021 13:41
@sindresorhus
Copy link
Member

Re d546fe0, why null and not undefined?


Context: sindresorhus/meta#7

@novemberborn
Copy link
Member Author

Re d546fe0, why null and not undefined?

Because I like null. However we can change it to undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants