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

WIP: chore(typescript): add TypeScript typings #16

Merged
merged 2 commits into from
Oct 11, 2018

Conversation

aaronmcadam
Copy link
Collaborator

@aaronmcadam aaronmcadam commented Sep 12, 2018

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:

  • Documentation: add instructions on adding the library types to tsconfig.json
  • Tests
  • Ready to be merged
  • Added myself to contributors table

I'm not sure if this is the correct type, but it does at least allow chaining to work
@aaronmcadam aaronmcadam changed the title chore(typescript): add TypeScript typings WIP: chore(typescript): add TypeScript typings Sep 12, 2018
Copy link
Collaborator

@sompylasar sompylasar left a comment

Choose a reason for hiding this comment

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

Looks right to me. There's an example here https://github.com/cypress-io/add-cypress-custom-command-in-typescript/blob/aff24be0/README.md but your code looks more correct and up-to-date than the one in the example.

@aaronmcadam
Copy link
Collaborator Author

I've heard about a way to test typings, I'm AFK but maybe we could enumerate the functions the dom library supports in order to make sure we cover everything. I'll look into it tomorrow. Thanks so much for helping out @sompylasar!

@sompylasar
Copy link
Collaborator

I've heard about a way to test typings

Please let me know when you find the way, I'd like to learn it for general awareness.

@aaronmcadam
Copy link
Collaborator Author

I think it's worth reaching out to @kentcdodds, as I don't want to add to his already busy workload for a workflow that he doesn't use day to day. My twitter is @aaromcadam @sompylasar if you want to pick things up in the morning (I'm UTC time)

@aaronmcadam
Copy link
Collaborator Author

@sompylasar Here's an intro to type testing with dtslint

there's a few things I'm unsure of:

* should we shadow the typings directory of dom-testing-library for easier maintainance?
* allBy methods: will the list of items be typed correctly?
} from 'dom-testing-library'

export namespace Cypress {
type GetByAttribute = (id: Matcher, options?: MatcherOptions) => Chainable
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@aaronmcadam
Copy link
Collaborator Author

Hi @sompylasar, could you give this another look when you get a chance? Thanks!

Copy link
Collaborator

@sompylasar sompylasar left a comment

Choose a reason for hiding this comment

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

LGTM (if it works, can't test it myself), thanks!

@kentcdodds kentcdodds merged commit f613149 into testing-library:master Oct 11, 2018
@kentcdodds
Copy link
Member

🎉 This PR is included in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kentcdodds
Copy link
Member

Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the other/MAINTAINING.md and CONTRIBUTING.md files (specifically the bit about the commit messages and the git hooks) and familiarize yourself with the code of conduct (we're using the contributor covenant). You might also want to watch the repo to be notified when someone files an issue/PR. Please continue to make PRs as you feel the need (you can make your branches directly on the repo rather than your fork if you want). Thanks! And welcome to the team :)

@aaronmcadam
Copy link
Collaborator Author

Do we have any active TypeScript users? These definitions aren't being picked up by VSCode for me.

@sebastian-ludwig
Copy link

Hi @aaronmcadam, you should probably use global augmentation instead

declare global {
  namespace Cypress {
    ...
  }
}

@marianban marianban mentioned this pull request Nov 2, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cypress-testing-library with typescript
4 participants