-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support assertions during teardown #2613
Comments
The teardown functions run at a point where we've already decided the test outcome.
That should be a part of the test itself. Why do you want to do this in a teardown? Perhaps you could wrap your test function to add the assertions? Alternatively there is a (I'm closing this issue for housekeeping purposes, but let's keep the conversation going.) |
While it could be a part of the test itself, additional work would be required to ensure the check if performed when trying to reuse code (or alternatively a rather unintuitive callback approach could be used). What I tried (which I prefer) resembles the following. import test from "ava";
import { createTestAssertLogger, LogLevel } from "../log-test-assert.js";
test("Foo bar", t => {
const log = createTestAssertLogger(t, [
[ LogLevel.INFO, "foobar" ]
]);
someFunction(log, ...);
}); With this approach the assertions are (relatively) cleanly defined, and there is the implication that the test completing with remaining log assertions would trigger a failure. A manual callback (ESLint providing a reminder) could also work, but I'm of the mindset that the extra boilerplate distracts from test composition.
Given |
There's also The work I started in #2435 would let you create custom |
As you noted, Your mention of a custom |
Yea. I have a |
Technically this can be achieved now via teardown functions, however output indicates that is not a supported behaviour via an error message like the following;
An example use case for this is asserting that a logging interface receives the expected output (specifically, that it has been called the expected number of times).
The text was updated successfully, but these errors were encountered: