testing-library / testing-library/eslint-plugin-testing-library

Internal: generate tests for all supported frameworks per rule

Open
#589 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

chore
Dominant language
TypeScript
Stars
1.1k
Forks
168
Avg merge
15h 44m
Merged PRs (30d)
14

Description

Plugin version

v5

What problem do you want to solve?

Quoting myself from #588:

Thinking about all the changes we did to test all rules for the corresponding Testing Library frameworks, I think it makes sense to add some improvements to our TestingLibraryRuleMeta and createRuleTester to automatically generate the test cases variations for indicated frameworks.

Your take on the correct solution?

In my mind, it could look like this:


// rules/foo.js
export default createTestingLibraryRule({
  // ...
  meta: {
    // ...
    supportedFrameworks: ['react', 'vue']
    // ^ we extend our TestingLibraryRuleMeta so it has this new required property,
    // which can be used also to autogenerate a table of compatible frameworks for each rule doc
  }
})

// test/lib/rules/foo.js
ruleTester.run(RULE_NAME, rule, {
  valid: [
    {
      code: `
      import { fireEvent } from '{TESTING_LIBRARY_FRAMEWORK}'
      //                                          ^ this placeholder gets replaced automatically,
      //                                             iterating over each value from supportedFrameworks
    
      await fireEvent.click(element)
      `
    }
  ]
})
Anything else?

No response

Do you want to submit a pull request to implement this change?

Yes

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the TestingLibraryRuleMeta and createRuleTester implementations, then compare the rule and test locations shown in rules/foo.js and test/lib/rules/foo.js. Check issue #588 for the existing framework-testing changes. Done means supportedFrameworks is represented in rule metadata and test cases can generate framework variations from the placeholder pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript, typescript
Domain
testing-qa, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.