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

fix: Remove errant export of GetByRoleMatcher, fixing type checking in some TS configurations #575

Merged

Conversation

fpapado
Copy link
Contributor

@fpapado fpapado commented Jan 30, 2024

What:

Follow-up to #143 , and the issue reported at #574.

Mixing export type with export = matchers can throw off TypeScript in some configurations. We do not need to export the matcher as a separate type, since the argument types are available in the matcher already.

I will admit, I do not know the exact combination of configuration that causes this issue. I think it would be desirable to include a test case for it, to ensure that we do not break it accidentally in the future.

The types are doing quite a lot of heavy lifting (types for explicit extend, types on globals/declaration merging, plus being "external" to the source), so perhaps we are not testing all the combinations. I am a bit surprised that we did not get this error in the existing tests, the double export sounds conceptually invalid. The issue at #574 has a reproduction, but paring it down to the size of the existing tests might be best.

Anyway, in terms of compatibility, I am confident that this is the best approach. By avoiding the extra export, we do not confuse TypeScript, and we are back in the previous status quo (exports = matchers only).

Why:

Avoiding unintended type changes, in some environments.

How:

By reverting what the TypeScript error was pointing at:

TS2309: An export assignment cannot be used in a module with other exported elements.

Checklist:

  • Documentation
  • Tests
  • Updated Type Definitions
  • Ready to be merged

I think this is ready to be merged, but the lack of an inverse test case is bothering me 😅

Please let me know if I can help in any way, and I'll give it a shot!

Mixing export type with export = matchers can throw off
TypeScript in some configurations. We do not need to export
the matcher as a separate type, since the argument types
 are available in the matcher already.
@@ -1,9 +1,5 @@
import {ARIARole} from 'aria-query'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be changed to?

import {type ARIARole} from 'aria-query'

@fpapado fpapado changed the title fix: Remove errant export of GetByRoleMatcher, fixing type checking in some TS configuraitons fix: Remove errant export of GetByRoleMatcher, fixing type checking in some TS configurations Jan 30, 2024
@fpapado fpapado mentioned this pull request Jan 31, 2024
@fpapado
Copy link
Contributor Author

fpapado commented Feb 2, 2024

Follow-up: we found in #574 that skipLibCheck is what causes this error to silently get ignored from the tests. I don't have a concrete suggestion for what to do with that; perhaps a separate tsconfig without skipLibCheck, but that would need to account for some library type errors that crop up.

Should we merge this to fix current breakage? Gentle ping @gnapse 😌

@gnapse gnapse enabled auto-merge (squash) February 5, 2024 12:55
@gnapse gnapse merged commit a93c0c4 into testing-library:main Feb 5, 2024
4 checks passed
Copy link

github-actions bot commented Feb 5, 2024

🎉 This PR is included in version 6.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

zemnmez-renovate-bot added a commit to zemn-me/monorepo that referenced this pull request Oct 5, 2024
##### [`v6.5.0](https://github.com/testing-library/jest-dom/releases/tag/v6.5.0)

##### Features

-   **toHaveValue:** Asserting aria-valuenow ([#479](testing-library/jest-dom#479)) ([acbf416](testing-library/jest-dom@acbf416))
##### [`v6.4.8](https://github.com/testing-library/jest-dom/releases/tag/v6.4.8)

##### Bug Fixes

-   Drop peerDependencies from package.json ([#610](testing-library/jest-dom#610)) ([faf534b](testing-library/jest-dom@faf534b))
##### [`v6.4.7](https://github.com/testing-library/jest-dom/releases/tag/v6.4.7)

##### Bug Fixes

-   Type definition of `toHaveClass` ([#611](testing-library/jest-dom#611)) ([5cc6298](testing-library/jest-dom@5cc6298))
##### [`v6.4.6](https://github.com/testing-library/jest-dom/releases/tag/v6.4.6)

##### Bug Fixes

-   Support [@starting-style](https://github.com/starting-style) ([#602](testing-library/jest-dom#602)) ([fd9ee68](testing-library/jest-dom@fd9ee68))
##### [`v6.4.5](https://github.com/testing-library/jest-dom/releases/tag/v6.4.5)

##### Bug Fixes

-   add js suffix to isEqualWith import ([#599](testing-library/jest-dom#599)) ([e8c8b13](testing-library/jest-dom@e8c8b13))
##### [`v6.4.4](https://github.com/testing-library/jest-dom/releases/tag/v6.4.4)

##### Bug Fixes

-   **infra:** codecoverage token addition ([#600](testing-library/jest-dom#600)) ([f03a582](testing-library/jest-dom@f03a582))
##### [`v6.4.3](https://github.com/testing-library/jest-dom/releases/tag/v6.4.3)

##### Bug Fixes

-   Updates role support for aria-required attribute in `toBeRequired` ([#590](testing-library/jest-dom#590)) ([20aca33](testing-library/jest-dom@20aca33))
##### [`v6.4.2](https://github.com/testing-library/jest-dom/releases/tag/v6.4.2)

##### Bug Fixes

-   Remove errant export of GetByRoleMatcher, fixing type checking in some TS configurations ([#575](testing-library/jest-dom#575)) ([a93c0c4](testing-library/jest-dom@a93c0c4))
##### [`v6.4.1](https://github.com/testing-library/jest-dom/releases/tag/v6.4.1)

##### Bug Fixes

-   Export type `TestingLibraryMatchers` from "./matchers" ([#576](testing-library/jest-dom#576)) ([dd1c4dd](testing-library/jest-dom@dd1c4dd))
##### [`v6.4.0](https://github.com/testing-library/jest-dom/releases/tag/v6.4.0)

##### Features

-   Add toHaveRole matcher ([#572](testing-library/jest-dom#572)) ([f7dc673](testing-library/jest-dom@f7dc673))
##### [`v6.3.0](https://github.com/testing-library/jest-dom/releases/tag/v6.3.0)

##### Features

-   Support for regular expressions in toHaveClass ([#563](testing-library/jest-dom#563)) ([9787ed5](testing-library/jest-dom@9787ed5))
##### [`v6.2.1](https://github.com/testing-library/jest-dom/releases/tag/v6.2.1)

##### Bug Fixes

-   Standalone types for "./matchers" export and add Bun support ([#566](testing-library/jest-dom#566)) ([5675b86](testing-library/jest-dom@5675b86))
##### [`v6.2.0](https://github.com/testing-library/jest-dom/releases/tag/v6.2.0)

##### Features

-   toHaveAccessibleDescription supports aria-description ([#565](testing-library/jest-dom#565)) ([1fb156c](testing-library/jest-dom@1fb156c))
##### [`v6.1.6](https://github.com/testing-library/jest-dom/releases/tag/v6.1.6)

##### Bug Fixes

-   Upgrade [@adobe/css-tools](https://github.com/adobe/css-tools) to v4.3.2 ([#553](testing-library/jest-dom#553)) ([b64b953](testing-library/jest-dom@b64b953))
##### [`v6.1.5](https://github.com/testing-library/jest-dom/releases/tag/v6.1.5)

##### Bug Fixes

-   support uppercase custom props in toHaveStyle ([#552](testing-library/jest-dom#552)) ([b7b7c6a](testing-library/jest-dom@b7b7c6a))
##### [`v6.1.4](https://github.com/testing-library/jest-dom/releases/tag/v6.1.4)

##### Bug Fixes

-   upgrade `@adobe/css-tools` to `4.3.1` to address vulnerability ([#532](testing-library/jest-dom#532)) ([44f1eab](testing-library/jest-dom@44f1eab))
##### [`v6.1.3](https://github.com/testing-library/jest-dom/releases/tag/v6.1.3)

##### Bug Fixes

-   proper [@jest/globals](https://github.com/jest/globals) import ([#530](testing-library/jest-dom#530)) ([5b492ac](testing-library/jest-dom@5b492ac))
##### [`v6.1.2](https://github.com/testing-library/jest-dom/releases/tag/v6.1.2)

##### Bug Fixes

-   bump [@adobe/css-tools](https://github.com/adobe/css-tools) for ESM support ([#525](testing-library/jest-dom#525)) ([b959a68](testing-library/jest-dom@b959a68))
##### [`v6.1.1](https://github.com/testing-library/jest-dom/releases/tag/v6.1.1)

##### Bug Fixes

-   **package.json:** update main and module file paths ([#523](testing-library/jest-dom#523)) ([853a3e5](testing-library/jest-dom@853a3e5))
##### [`v6.1.0](https://github.com/testing-library/jest-dom/releases/tag/v6.1.0)

##### Features

-   Publish ESM and CJS (testing-library/jest-dom#519)
##### [`v6.0.1](https://github.com/testing-library/jest-dom/releases/tag/v6.0.1)

##### Bug Fixes

-   matchers type is making the global expect unsafe ([#513](testing-library/jest-dom#513)) ([bdb34f1](testing-library/jest-dom@bdb34f1))
##### [`v6.0.0](https://github.com/testing-library/jest-dom/releases/tag/v6.0.0)

##### Features

-   local types, supporting jest, [@jest/globals](https://github.com/jest/globals), vitest ([#511](testing-library/jest-dom#511)) ([4b764b9](testing-library/jest-dom@4b764b9))

##### BREAKING CHANGES

-   Removes the extend-expect script. Users should use
    the default import path or one of the new test platform-specific
    paths to automatically extend the appropriate "expect" instance.

extend-expect was not documented in the Readme, so this change should
have minimal impact.

Users can now use the following import paths to automatically extend
"expect" for their chosen test platform:

-   [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) - jest ([@types/jest](https://github.com/types/jest))
-   @testing-library/jest-dom/jest-globals - [@jest/globals](https://github.com/jest/globals)
-   @testing-library/jest-dom/vitest - vitest

For example:

import '@testing-library/jest-dom/jest-globals'

Importing from one of the above paths will augment the appropriate
matcher interface for the given test platform, assuming the import
is done in a .ts file that is included in the user's tsconfig.json.

It's also (still) possible to import the matchers directly without
side effects:

import \* as matchers from '@testing-library/jest-dom/matchers'

-   Update kcd-scripts
-   Drop node < 14
github-merge-queue bot pushed a commit to zemn-me/monorepo that referenced this pull request Oct 5, 2024
##### [`v6.5.0](https://github.com/testing-library/jest-dom/releases/tag/v6.5.0)

##### Features

-   **toHaveValue:** Asserting aria-valuenow ([#479](testing-library/jest-dom#479)) ([acbf416](testing-library/jest-dom@acbf416))
##### [`v6.4.8](https://github.com/testing-library/jest-dom/releases/tag/v6.4.8)

##### Bug Fixes

-   Drop peerDependencies from package.json ([#610](testing-library/jest-dom#610)) ([faf534b](testing-library/jest-dom@faf534b))
##### [`v6.4.7](https://github.com/testing-library/jest-dom/releases/tag/v6.4.7)

##### Bug Fixes

-   Type definition of `toHaveClass` ([#611](testing-library/jest-dom#611)) ([5cc6298](testing-library/jest-dom@5cc6298))
##### [`v6.4.6](https://github.com/testing-library/jest-dom/releases/tag/v6.4.6)

##### Bug Fixes

-   Support [@starting-style](https://github.com/starting-style) ([#602](testing-library/jest-dom#602)) ([fd9ee68](testing-library/jest-dom@fd9ee68))
##### [`v6.4.5](https://github.com/testing-library/jest-dom/releases/tag/v6.4.5)

##### Bug Fixes

-   add js suffix to isEqualWith import ([#599](testing-library/jest-dom#599)) ([e8c8b13](testing-library/jest-dom@e8c8b13))
##### [`v6.4.4](https://github.com/testing-library/jest-dom/releases/tag/v6.4.4)

##### Bug Fixes

-   **infra:** codecoverage token addition ([#600](testing-library/jest-dom#600)) ([f03a582](testing-library/jest-dom@f03a582))
##### [`v6.4.3](https://github.com/testing-library/jest-dom/releases/tag/v6.4.3)

##### Bug Fixes

-   Updates role support for aria-required attribute in `toBeRequired` ([#590](testing-library/jest-dom#590)) ([20aca33](testing-library/jest-dom@20aca33))
##### [`v6.4.2](https://github.com/testing-library/jest-dom/releases/tag/v6.4.2)

##### Bug Fixes

-   Remove errant export of GetByRoleMatcher, fixing type checking in some TS configurations ([#575](testing-library/jest-dom#575)) ([a93c0c4](testing-library/jest-dom@a93c0c4))
##### [`v6.4.1](https://github.com/testing-library/jest-dom/releases/tag/v6.4.1)

##### Bug Fixes

-   Export type `TestingLibraryMatchers` from "./matchers" ([#576](testing-library/jest-dom#576)) ([dd1c4dd](testing-library/jest-dom@dd1c4dd))
##### [`v6.4.0](https://github.com/testing-library/jest-dom/releases/tag/v6.4.0)

##### Features

-   Add toHaveRole matcher ([#572](testing-library/jest-dom#572)) ([f7dc673](testing-library/jest-dom@f7dc673))
##### [`v6.3.0](https://github.com/testing-library/jest-dom/releases/tag/v6.3.0)

##### Features

-   Support for regular expressions in toHaveClass ([#563](testing-library/jest-dom#563)) ([9787ed5](testing-library/jest-dom@9787ed5))
##### [`v6.2.1](https://github.com/testing-library/jest-dom/releases/tag/v6.2.1)

##### Bug Fixes

-   Standalone types for "./matchers" export and add Bun support ([#566](testing-library/jest-dom#566)) ([5675b86](testing-library/jest-dom@5675b86))
##### [`v6.2.0](https://github.com/testing-library/jest-dom/releases/tag/v6.2.0)

##### Features

-   toHaveAccessibleDescription supports aria-description ([#565](testing-library/jest-dom#565)) ([1fb156c](testing-library/jest-dom@1fb156c))
##### [`v6.1.6](https://github.com/testing-library/jest-dom/releases/tag/v6.1.6)

##### Bug Fixes

-   Upgrade [@adobe/css-tools](https://github.com/adobe/css-tools) to v4.3.2 ([#553](testing-library/jest-dom#553)) ([b64b953](testing-library/jest-dom@b64b953))
##### [`v6.1.5](https://github.com/testing-library/jest-dom/releases/tag/v6.1.5)

##### Bug Fixes

-   support uppercase custom props in toHaveStyle ([#552](testing-library/jest-dom#552)) ([b7b7c6a](testing-library/jest-dom@b7b7c6a))
##### [`v6.1.4](https://github.com/testing-library/jest-dom/releases/tag/v6.1.4)

##### Bug Fixes

-   upgrade `@adobe/css-tools` to `4.3.1` to address vulnerability ([#532](testing-library/jest-dom#532)) ([44f1eab](testing-library/jest-dom@44f1eab))
##### [`v6.1.3](https://github.com/testing-library/jest-dom/releases/tag/v6.1.3)

##### Bug Fixes

-   proper [@jest/globals](https://github.com/jest/globals) import ([#530](testing-library/jest-dom#530)) ([5b492ac](testing-library/jest-dom@5b492ac))
##### [`v6.1.2](https://github.com/testing-library/jest-dom/releases/tag/v6.1.2)

##### Bug Fixes

-   bump [@adobe/css-tools](https://github.com/adobe/css-tools) for ESM support ([#525](testing-library/jest-dom#525)) ([b959a68](testing-library/jest-dom@b959a68))
##### [`v6.1.1](https://github.com/testing-library/jest-dom/releases/tag/v6.1.1)

##### Bug Fixes

-   **package.json:** update main and module file paths ([#523](testing-library/jest-dom#523)) ([853a3e5](testing-library/jest-dom@853a3e5))
##### [`v6.1.0](https://github.com/testing-library/jest-dom/releases/tag/v6.1.0)

##### Features

-   Publish ESM and CJS (testing-library/jest-dom#519)
##### [`v6.0.1](https://github.com/testing-library/jest-dom/releases/tag/v6.0.1)

##### Bug Fixes

-   matchers type is making the global expect unsafe ([#513](testing-library/jest-dom#513)) ([bdb34f1](testing-library/jest-dom@bdb34f1))
##### [`v6.0.0](https://github.com/testing-library/jest-dom/releases/tag/v6.0.0)

##### Features

-   local types, supporting jest, [@jest/globals](https://github.com/jest/globals), vitest ([#511](testing-library/jest-dom#511)) ([4b764b9](testing-library/jest-dom@4b764b9))

##### BREAKING CHANGES

-   Removes the extend-expect script. Users should use
    the default import path or one of the new test platform-specific
    paths to automatically extend the appropriate "expect" instance.

extend-expect was not documented in the Readme, so this change should
have minimal impact.

Users can now use the following import paths to automatically extend
"expect" for their chosen test platform:

-   [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) - jest ([@types/jest](https://github.com/types/jest))
-   @testing-library/jest-dom/jest-globals - [@jest/globals](https://github.com/jest/globals)
-   @testing-library/jest-dom/vitest - vitest

For example:

import '@testing-library/jest-dom/jest-globals'

Importing from one of the above paths will augment the appropriate
matcher interface for the given test platform, assuming the import
is done in a .ts file that is included in the user's tsconfig.json.

It's also (still) possible to import the matchers directly without
side effects:

import \* as matchers from '@testing-library/jest-dom/matchers'

-   Update kcd-scripts
-   Drop node < 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants