mui / mui/material-ui

adding testkit package or testkit driver to each component

Open
#30,516 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

scope: all components test waiting for 👍
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Summary 💡

When developing a real app with many reusable components and writing tests for it, it is essential to have a testkit driver for each component so it will be much easier and faster to write unit-component tests for my app.

Examples 🌈

An Example:

Today in order to select some value of the <Select /> component in tests, I'll need to write the following code:

function selectOptionAt(index: number) {
  const wrapperEl = getByTestId(htmlContainer, 'my-test-id')
  fireEvent.mouseDown(getByRole(wrapperEl, 'button'))
  const options = getAllByRole(document.body, 'option')
  return fireEvent.click(options[index])
}

and for each component that contains <Select /> component which I'd like to test, I'll need to copy-paste the above code.
Instead, I'd like to have some like the following:

import { SelectTestkit } from '@mui/material/testkits'
// ...
const myComponentDriver (container: HTMLElement) {
  const selectTk = SelectTestkit(container)
  return {
    selectOptionAt(index: number) {
      selectTk.selectOptionAt(index)
    }
  }
}
Motivation 🔦

I want to believe the motivation is clear from the example above. There might be a better way to achieve what I was doing in my code but again, this is just an example of code that lacking a specific driver for such basic component, making me copy-pasting this piece of code from one test to another. It both wastes a lot of time and hard to maintain in case changes are needed.

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

No repository files or tests are named. Start by reviewing the existing component test patterns and the Select example from the issue, then determine the scope and API for adding testkit drivers across components; done would mean reusable drivers support component tests without repeated interaction code.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.