-
Notifications
You must be signed in to change notification settings - Fork 153
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
Cypress-testing-library with typescript #12
Comments
Sorry, I don't use typescript :-/ I don't know what could be wrong. |
Wrong are missing typings for the mixed-in functions. Someone needs to adds typings to describe the additional functions this library attaches to the |
I guess this typings will be enough. |
@YozhEzhi Yes, but not literally these files. |
If we can get the right typings, we can configure our tests to use them by adding the name of the package to the {
"compilerOptions": {
"strict": true,
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "cypress-testing-library"]
}
} |
@sompylasar Do you know of a good way we can share the types from |
@bahmutov Could you provide any guidance here? |
I've tried the following, which at least stops the error showing up: declare global {
namespace Cypress {
interface Chainable<Subject = any> {
getByTestId<S = string>(x: string): Chainable<S>;
}
}
} |
@aaronmcadam Try importing |
@aaronmcadam I gave it a secont thought, and the answer is no, you should not reuse from dom-testing-library because the function signatures differ (e.g the return value type), cypress-testing-library provides wrapper functions around dom-testing-library which are not the functions exported from dom-testing-library. Copying the definitions and changing the types to match the wrapper signatures is the right way. Although maybe there is already an automated type mapping in recent TypeScript so maybe this can be used to map them (but this means it'll require latest TypeScript to read these definitions). |
Hi @sompylasar! Thanks for your thoughts, that helps a lot. I've started #16 to try to work out how to solve this. Could you take a look? I'm a bit unsure on how best to implement this in a maintainable way. |
@aaronmcadam Reviewed, thanks.
Yes I'm not sure either. The functions from dom-testing-library are mapped dynamically into cypress commands (function wrappers) in cypress-testing-library by looping over the queries object, but they need static typing. Unless there's a way to statically map types of dom-testing-library functions into types of cypress-testing-library custom command functions, the list of functions will have to be maintained and kept in sync manually. |
What's the status on this issue? Anything a non-typescript user can do to help? The problem I encounter is that it breaks the |
I'm not personally actively working on this issue. I don't track typescript issues very closely myself. |
Hi @freddydumont I'm waiting on some feedback as to whether these types are correct. I do use TypeScript daily but I'd like some feedback from a maintainer |
The PR is here: #16 |
Thanks for the replies guys. So who could review your PR? @sompylasar ? |
Yeah it needs another look from him @freddydumont |
@aaronmcadam @freddydumont Sorry haven't had time to look earlier, PR approved, assuming you checked that it works, I can't test it myself as I don't have a Cypress+TypeScript setup at hand. |
Also the cypress-testing-library might need to be updated to the latest dom-testing-library, its public API has updated recently in some regards (don't remember if the changes affect the queries anyhow), please have a look at recent changes. |
**What**: Attempts to fix #12. I've only added support for `getByTestId` to ensure that I've done things correctly. I wonder if there's an easy way to keep up to date with `dom-testing-library`? **Why**: For TypeScript support **How**: Added a `typings` directory and added a reference to `package.json`. I've tried to copy how cypress adds its own types for chainable methods and custom commands: https://github.com/cypress-io/add-cypress-custom-command-in-typescript/blob/master/README.md **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> * [ ] Documentation: add instructions on adding the library types to tsconfig.json * [ ] Tests * [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? --> * [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> <!-- feel free to add additional comments -->
🎉 This issue has been resolved in version 2.3.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Cypress-testing-library not working with typescript.
The text was updated successfully, but these errors were encountered: