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.

default cypress config is not custom command friendly

See original GitHub issue

Current Behavior

As soon as we start importing stuff in the same file as where Cypress namespace is redeclared (default file is commands.ts), TS compilation is broken because none of the added custom methods is recognized anymore.
As a non typescript/cypress expert it took me several hours to discover that and it is still unclear to me why it is happening :S

Expected Behavior

There should be a separate file which only contains the redecleration of Cypress namespace. This setup seems to work.
It also have to be imported in support/index.ts. Full fix example:

src/support
 - commands.ts
 - index.ts
 - ns.ts
// index.ts
import './commands';
import './ns';
// ns.ts
declare namespace Cypress {
  interface Chainable<Subject> {
    login(email: string, password: string): void;
  }
}
// commands.ts
Cypress.Commands.add('login', (email, password) => {
  console.log('Custom command example: Login', email, password);
}

Steps to Reproduce

  • create an E2E app
  • add a custom command file under src/support
// src/support/my-command.ts
export function addCommand(): void {}
  • do an import anywhere in commands.ts:
import { addCommand } from './my-command'

Failure Logs

default generated app.spec.ts does not understand cy.login(...) anymore

TS2339: Property ‘login’ does not exist on type ‘cy & EventEmitter’.

Environment

nx : Not Found @nrwl/angular : 10.3.2 @nrwl/cli : 10.3.2 @nrwl/cypress : 10.3.2 @nrwl/eslint-plugin-nx : Not Found @nrwl/express : Not Found @nrwl/jest : 10.3.2 @nrwl/linter : 10.3.2 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : Not Found @nrwl/schematics : Not Found @nrwl/tao : 10.3.2 @nrwl/web : Not Found @nrwl/workspace : 10.3.2 typescript : 4.0.5

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
Abildtoftcommented, May 6, 2021

This issue has been automatically marked as stale because it hasn’t had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

Would it be possible to reopen the issue?

1reaction
Abildtoftcommented, Jul 29, 2021

I can also confirm that the workaround with a specific file for the namespace works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration - Cypress Documentation
This guide is for Cypress 10 and the new JavaScript configuration file format. If you are on an older version of Cypress that...
Read more >
Configurations in Cypress and How to Disable Default ...
What are Configurations in Cypress? What are default configurations provided by Cypress? How to override & disable default configurations?
Read more >
Useful custom Cypress commands - Ron Valstar
Some useful Cypress custom commands to make your tests cleaner. ... It is so ridiculously user-friendly that writing tests is no longer a ......
Read more >
The 32+ ways of selective testing with Cypress: a unified ...
Handle the environments in config files, and define a custom environment variable ... cypress run - very similar to command line style.
Read more >
cypress-wait-until - npm
Use this plugin to wait for everything not expected by Cypress wait. ... 'This is a custom error message', // overrides the default...
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