Skip to content
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: no-controller-actions #35

Open
codejedi365 opened this issue Nov 13, 2021 · 0 comments
Open

feat: no-controller-actions #35

codejedi365 opened this issue Nov 13, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@codejedi365
Copy link
Collaborator

Feature Request

Add a lint rule that warns about using direct actions from being used in a test

Problem

Brittle test cases when simple features on the UI change. It causes tests to need to be re-written and evaluated which is against the concept of test like a user would.

So the goal is to have tests that are flexible enough to focus on only the features that are provided and not be tightly coupled to how the interface is constructed. The page model abstraction recommended by TestCafe demonstrates how to build tests that maintain their integrity but handle interaction changes. Hopefully, eslint can provide incentive and enforcement in implementing the page model construct amongst all test cases.

Expected behavior

// page.test.js - invalid example
// Derived from https://testcafe.io/documentation/402826/guides/concepts/page-model
test('Text typing basics', async t => {
    await t
        .typeText('#developer-name', 'Peter')
        .click("#submit")
        .expect(Selector('#developer-name').value).eql('Parker');
});
# Run Lint
eslint ./tests/page.test.js

Should return an warning on line 5 & 6, highlighting the typeText(...) & click(...). Recommend abstracting away actions into readable action methods on a page and calling the actions with parameters.

Ideal page model with abstracted action methods should look like this:

// page.test.js - desired implementation
import { t } from "testcafe"
import { page } from "./models"

test('Submit a developer name and check the header', async t => {
    await page.submitName('Peter');
    await t.expect(page.header.userName.innerText).eql('Thank you, Peter!');
});
@codejedi365 codejedi365 added the enhancement New feature or request label Nov 13, 2021
@codejedi365 codejedi365 self-assigned this Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant