default cypress config is not custom command friendly
See original GitHub issueCurrent 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:
- Created 3 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Would it be possible to reopen the issue?
I can also confirm that the workaround with a specific file for the namespace works.