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

fix(types): allow all elements

Open nickserv opened this issue 5 years ago • 10 comments

Port of testing-library/react-testing-library#833

Checklist:

  • [x] Documentation added to the docs site
  • [ ] Tests
  • [x] Typescript definitions updated
  • [ ] Ready to be merged

nickserv avatar Nov 20 '20 22:11 nickserv

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit cdc5980e4753e16d5604803a3fffb22ccd31588c:

Sandbox Source
react-testing-library-examples Configuration

codesandbox-ci[bot] avatar Nov 20 '20 22:11 codesandbox-ci[bot]

@nickmccurdy I saw this one: https://github.com/testing-library/react-testing-library/issues/837 I think it might be because this wasn't implemented in dom-testing-library but I might get it wrong.. do you think it's related?

MatanBobi avatar Nov 25 '20 14:11 MatanBobi

Here's the error we're getting in CI:

[typecheck] Error: /home/runner/work/dom-testing-library/dom-testing-library/types/__tests__/type-tests.ts:164:9
[typecheck] ERROR: 164:9  expect  [email protected] compile error: 
[typecheck] Type 'Element' is missing the following properties from type 'HTMLSpanElement': accessKey, accessKeyLabel, autocapitalize, dir, and 107 more.
[typecheck] 
[typecheck]     at /home/runner/work/dom-testing-library/dom-testing-library/node_modules/dtslint/bin/index.js:206:19
[typecheck]     at Generator.next (<anonymous>)
[typecheck]     at fulfilled (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/dtslint/bin/index.js:6:58)
[typecheck] npm run typecheck --silent exited with code 1

kentcdodds avatar Nov 30 '20 18:11 kentcdodds

Here's the CI failure:

[lint] 
[lint] Oops! Something went wrong! :(
[lint] 
[lint] ESLint: 7.14.0
[lint] 
[lint] TypeError: Cannot read property 'name' of undefined
[lint] Occurred while linting /home/runner/work/dom-testing-library/dom-testing-library/src/__tests__/element-queries.js:220
[lint]     at check (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint-plugin-jest-dom/dist/rules/prefer-in-document.js:39:27)
[lint]     at CallExpression[callee.object.callee.name='expect'][callee.property.name=/(toHaveLength|toBeDefined|toBeNull)/] (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint-plugin-jest-dom/dist/rules/prefer-in-document.js:97:7)
[lint]     at /home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint/lib/linter/safe-emitter.js:45:58
[lint]     at Array.forEach (<anonymous>)
[lint]     at Object.emit (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
[lint]     at NodeEventGenerator.applySelector (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
[lint]     at NodeEventGenerator.applySelectors (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
[lint]     at NodeEventGenerator.enterNode (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
[lint]     at CodePathAnalyzer.enterNode (/home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
[lint]     at /home/runner/work/dom-testing-library/dom-testing-library/node_modules/eslint/lib/linter/linter.js:952:32

I think it's something wrong with the jest-dom/prefer-in-document eslint plugin rule. We're in violation of that rule a bunch in our repo (many of our tests were in place before that assertion existed). Looks like this is a bug in @testing-library/eslint-plugin-jest-dom and also something maybe we should update?

Unfortunately this is completely unrelated to this PR, but we should probably get it fixed before merging anything else.

kentcdodds avatar Nov 30 '20 21:11 kentcdodds

I'm also not opposed to just disabling the rule for now.

kentcdodds avatar Nov 30 '20 21:11 kentcdodds

Yeah that rule is not in the recommended list yet until it gets a little more vetting. There is a PR in flight that addresses some stability on the rule though.

benmonro avatar Nov 30 '20 21:11 benmonro

https://github.com/testing-library/eslint-plugin-jest-dom/pull/107 fixes the crash but then we get 76 lint errors, so I'll disable it and we can fix those issues separately.

nickserv avatar Nov 30 '20 21:11 nickserv

@nickmccurdy the rule is autofixing. fwiw. :)

benmonro avatar Nov 30 '20 21:11 benmonro

Codecov Report

Merging #834 (cdc5980) into master (010f8be) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #834   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        26           
  Lines          934       934           
  Branches       286       286           
=========================================
  Hits           934       934           
Impacted Files Coverage Δ
src/get-queries-for-element.js 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 010f8be...cdc5980. Read the comment docs.

codecov[bot] avatar Nov 30 '20 22:11 codecov[bot]

Hi folks, Happy New Year! Is resolving those last 3 conflicts on anybody's radar? (The nextjs "with-typescript-eslint-jest" kit features a test util that overrides render, but it breaks on typing the RenderResult; looks like this PR will fix it.) Thanks for all your work on this awesome library! Slainte, Chris

cweekly avatar Jan 06 '21 14:01 cweekly