-
Notifications
You must be signed in to change notification settings - Fork 2
Description
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
class Hub {
title: Selector;
constructor() {
this.title = main.find("h1").withText("Village Hub");
}
async isOpen() {
// Verify that we are on the hub page
t.expect(this.title.exists).ok("We have landed on the Hub page", {
// it takes a while to go from the firebase popup to the hub page when signin
// from the Top page
timeout: 5000,
});
}
}Test:
// Scenario outline: A user can signin from different entrypoints
Object.entries(entrypoints).forEach(
([path, [signinButton, providerButton]]) => {
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);
await Hub.isOpen();
});
}
);The test above raises an eslint warning Please ensure your test has at least one expect, althought it has one in the isOpen 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#L102
Expected 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
rules:
testcafe-community/missing-expect:
- aliases:
- isOpen