cypress-testing-library icon indicating copy to clipboard operation
cypress-testing-library copied to clipboard

Cannot import `ByRoleMatcher` (and others) from @testing-library/cypress

Open srflp opened this issue 3 years ago • 0 comments

  • cypress-testing-library version: 8.0.7
  • node version: v18.12.1
  • pnpm version: 7.16.1

My package.json

  "devDependencies": {
    "@faker-js/faker": "^7.6.0",
    "@testing-library/cypress": "^8.0.3",
    "@typescript-eslint/eslint-plugin": "^5.43.0",
    "@typescript-eslint/parser": "^5.43.0",
    "cypress": "^11.1.0",
    "eslint": "^8.27.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-plugin-cypress": "^2.12.1",
    "husky": "^8.0.2",
    "lint-staged": "^13.0.3",
    "prettier": "^2.7.1",
    "typescript": "~4.8.4"
  },
  "dependencies": {}

I wanted to import ByRoleMatcher type from @testing-library/cypress, since this type is used as an argument type for findByRole(id: ByRoleMatcher, options?: ByRoleOptions) function from @testing-library/cypress.

Problem:

ByRoleMatcher is used by @testing-library/cypress but is not exported by it. And I want to use this type in my project.

Suggested solutions:

  • reexport ByRoleMatcher from @testing-library/cypress
  • mark @testing-library/dom as a peer dependency (I'm not sure if it would fix it)
  • inform TypeScript users that they should also npm/yarn/pnpm install -D @testing-library/dom to have access to all of the types

srflp avatar Nov 19 '22 19:11 srflp