-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: More flexible missing-expect rule #54
Comments
@AdrienLemaire, thank you for the great write up and example information. I definitely can see how this could be problematic if the assertions are abstracted out of the test function scope. I will have to do some more research on the internals available within ESLint because of the traditional Abstract Syntax Tree (AST) and the hook mechanism don't actually compile/load the code to allow for "following" of functions. As my understanding goes, ESLint isolates the current file that is being linted which means following external (imported) files would be out-of-scope. I estimate it would need to somehow follow the import and run an AST on the secondary file and spider out from there, which might not be doable with adequate performance. Your alternative of aliased expect functions is a great recommendation and I think that would be much simpler to implement at the moment. I am curious if you would have any side-effects from a generic Separately, I want to offer my opinion on test structure in case that might stem a different idea or direction for you and your team. I have debated the idea of abstractions related to assertions due to the extension of the idea of a // hub.test.js
import Hub from "./page-models/hub"
// global constants, For test readability
MILLISECONDS = 1
SECONDS = 1000 * MILLISECONDS
// it takes a while to go from the firebase popup to the hub page when signing-in
// from the Top page
SIGN_IN_THRESHOLD = 5 * SECONDS
test(`Signin flow: ${path}`, async (t) => {
// Open signin modal and click the user's provider button
await t.click(signinButton).click(providerButton);
await fillCredentials(user.email, user.password);
// NOTE: string provided is for when the test fails. Your msg looks like a success message to me.
// function signature = t.expect().ok(errMsg, opts)
// from https://testcafe.io/documentation/402716/reference/test-api/testcontroller/expect/ok
// message = "An assertion message displayed in the report if the test fails"
await t.expect(Hub.title.exists).ok("Failed to reach hub page", {
timeout: SIGN_IN_THRESHOLD
});
}); Thank you for indulging my discourse and I recognize test structure is up to your team. I'm glad I thought about this topic again as I notice your test |
@codejedi365 thank you for the great reply and side notes. One reason I love OSS is thanks to contributors like you. I suppose we'll keep our expects in test functions for the time being, and we'll follow the TestCafe recommendations. It is fair enough to close this issue as "wontfix because encourages bad practices", and maybe mentioning this good practice in the doc could be useful to people like me 👍 |
Feature Request
Make missing-expect smarter by detecting expect statements in helper functions.
Problem || Goal
An expect can become verbose, and moving it to an helper function or class method make for tests easier to read and maintain
Example page
Test:
The test above raises an eslint warning
Please ensure your test has at least one expect
, althought it has one in theisOpen
method.This is because the rule searches for the exact term
expect
in the test code in https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/lib/rules/missing-expect.ts#L102Expected behavior
No warning should be raised.
Potential solutions
Not sure about the effort required to open helpers / class methods and parse their code.
An alternative would be to add an eslint parameter to specify alternate expect statements
The text was updated successfully, but these errors were encountered: