-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
chore: Add extra chainer types for auto-complete #1059
chore: Add extra chainer types for auto-complete #1059
Conversation
(chainers: string, value?: any): Chainable<Subject> | ||
(chainers: string, method: string, value: any): Chainable<Subject> | ||
(chainers: string, value: any, match: any): Chainable<Subject> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value: any
is more accurate here. The first argument isn't always a string for 2-argument assertions.
Is there any way we can add a user description for each of the assertions? That would be an even better experience. |
I'm really excited about this btw, this is huge! |
Another question - since we know the type already, can we have the assertions be filtered by this? Example: // at this point we know mostly just jquery attertions matter here
// so we should't show assertions related to sinon, chai that are not applicable
cy.get('element').should(...) |
Another question - can we get autocompletion for explict assertions like this: cy.wrap('foo').should((str) => {
expect(str).to.eq('foo')
}) |
Yes! We can add JSDoc to each chainer type.
I forgot to mention VSCode uses the TypeScript language service for JavaScript as well, so these helpers will show up when using JavaScript as well. Theoretically any IDE or editor using TypeScript language services (I know many do)!
I have types here that can do this: https://gist.github.com/NicholasBoll/57605bfd2176603dd75ea0e54afb2ce0#file-cypress-d-ts-L1427. Further down in the file are That does require breaking up the
This is already supported by #1048. It added |
@brian-mann I used https://docs.cypress.io/guides/references/assertions.html#Chai as a template for what chainers should be included, but there isn't descriptions there. Do you think the docs and the types should both contain descriptions? I think Chai's own API might be a good starting point: http://chaijs.com/api/bdd/ |
I would consider that we do have descriptions in the docs because we show an example of each assertion usage. That's likely enough for most users. However the |
Sure. I know VSCode supports examples with markdown which can be helpful in the tooltip. I would assume other editors can do that as well. I'll add those comments to the chainer methods and show what that looks like on a video. I should be able to get to that later today |
Liking what I'm seeing 👍 |
that is great @NicholasBoll |
😀 There must be a rush on this. This PR has the auto-complete, but not the extra docs in the last screenshot. I'll continue to add JSDocs to the auto-complete and open another PR. |
Sure. When a PR is opened and it passes it's hard to keep up with it if its partially done. I thought this might be the case but we are doing a release tonight so just wanted to get it in. Each PR needs an associated issue so I can track the milestones and use it to generate the changelog. |
Good call. The docs don't add any features, just improve it. Better to get incrementally better UX to people. |
This looks great, but I'm using intellij and I do have autocomplete working for things like .should, but autocomplete is not working for these string assertions, any idea why? edit: I got this working after setting up typescript support via webpack, I made many changes but I believe the change that allowed the auto completion to work was adding: |
@daveerwin1 Care to share your tsconfig.json ? :) I'm having the same issue right now and I can't get autocomplete to work with
|
@Niceplace That is what I have in tsconfig.json |
Ohhh that guy’s blog posts...
…Sent from my iPhone
On Mar 22, 2019, at 16:09, daveerwin1 ***@***.***> wrote:
@Niceplace That is what I have in tsconfig.json
I found this blog post which helped me get it working:
https://glebbahmutov.com/blog/use-typescript-with-cypress/
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
This adds the 4th item in #1040.
This change only adds auto-complete and help. Cypress supports strings for
cy.shoud
andcy.and
. This PR adds a lot of happy-path assertions that help guide to what's available instead of justshould: (assertion: string, value?: any, matcher:? any): Chainable<Subject>
. If an assertion type isn't listed in the types, it will fall back to a simple string assertion. This does not actually add any type safety, just a nicer developer experience.Here's a video of the auto-complete support in VS-Code with this change: