question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding custom commands throws IDE errors

See original GitHub issue

Current behavior:

When adding a new custom command, like Cypress.Commands.add('login', (user) => {

JetBrains (GoLand in my case) doesn’t recognise the command and throws an error on it. Screenshot 2020-07-30 at 11 51 25

This shows errors all they way up the file tree in my IDE

Desired behavior:

I would like to be able to register the command to the IDE to prevent theseissues

Versions

Goland 2020.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
jennifer-shehanecommented, Aug 4, 2020

After relooking at this, it seems that adding the reference to the index.d.ts file at the top of the support/index.ts file will cause the types to work correctly.

@rkorebrits Can you confirm that this fixes your types?

There’s some discussion here on this situation.

support/index.ts

/// <reference path="../support/index.d.ts" />

Cypress.Commands.add('login', (userType, options = {}) => {})
3reactions
jennifer-shehanecommented, Aug 3, 2020

I’ve confirmed that this example from our docs to define Type definitions for custom commands does not work when the support/index file where the custom command is defined is a TypeScript file. If you renamed the support/index.ts file to support/index.js (being a JavaScript file) - the type definition works for the spec.

Repro

cypress/support/index.d.ts

declare namespace Cypress {
  interface Chainable {
    login(user: any): void
  }
}

cypress/support/index.ts - works if cypress/support/index.js

Cypress.Commands.add('login', (userType, options = {}) => {})

cypress/integration/spec.ts

it('login', () => {
  cy.login('admin')
})
Screen Shot 2020-08-03 at 3 35 00 PM

Not sure if this is some bug or issue with our documentation that needs updating.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Exceptions in Your Custom Command
If you have a custom command and an exception is thrown within your code, good programming practice is to handle that exception and...
Read more >
Cypress custom command is not recognized when invoked
login(testuser, testpwd) , but I'm getting the following error message: TypeError: cy.login is not a function . The docs say that /cypress/ ...
Read more >
TypeScript - Cypress Documentation
When adding custom commands to the cy object, you can manually add their types to avoid TypeScript errors. For example if you add...
Read more >
Troubleshoot development errors with Office Add-ins
Learn how to troubleshoot development errors in Office Add-ins. ... The add-in has a custom Add-in Command but you are trying to run...
Read more >
A Definitive Guide to Handling Errors in JavaScript - Kinsta
Types of Errors in JavaScript; Creating Custom Error Types ... JavaScript allows you to throw anything literally with the throw command.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found