Tech stack: Angular v15 and Cypress V12
Despite successful runs of my component and end-to-end tests, I encounter peculiar terminal errors while running the tests.
The issue could potentially stem from my Cypress configuration for shared commands.
Here are my shared commands:
declare global {
namespace Cypress {
interface Chainable {
loginAs(role?: string): Chainable<any>,
isWelcomePage(): Chainable<any>,
openMenu(): Chainable<any>,
}
}
}
Cypress.Commands.add('loginAs', (role?: string) => {
const user = Cypress.env('user');
cy.visit(Cypress.env('local'));
cy.get('#mat-input-0', { timeout: 30000 }).should('be.visible').type(user.email);
cy.get('#mat-input-1', { timeout: 30000 }).should('be.visible').type(user.password);
cy.get('.btn').click({ force: true });
});
This is my cypress configuration:
import { defineConfig } from "cypress";
const { verifyDownloadTasks } = require('cy-verify-downloads');
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
on('task', verifyDownloadTasks)
},
specPattern: "cypress/e2e/**/*.cy.ts",
},
chromeWebSecurity: false,
screenshotsFolder: "cypress/snapshots",
trashAssetsBeforeRuns: true,
viewportWidth: 1400,
viewportHeight: 1200,
video: false,
defaultCommandTimeout: 10000,
env: {
local: "http://localhost:4200/",
staging: "hidden",
backend: "hidden",
user: {
email: "hidden",
password: "hidden",
},
},
component: {
devServer: {
framework: "angular",
bundler: "webpack",
},
specPattern: "**/*.cy.ts",
},
});
This is the terminal errors:
https://i.sstatic.net/3qBnk.png
Exact error messages
- Property 'loginAs' does not exist on type 'cy & CyEventEmitter'.
Current Attempt:
Tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": false,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "ES2022",
"module": "es2020",
"allowJs": true,
"lib": [
"es2020",
"dom"
],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"types": ["cypress", "cy-verify-downloads"],
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": false,
"strictInputAccessModifiers": false,
"strictTemplates": false
},
"include": [
"./src",
"./cypress/support/index.d.ts"
]
}
index.d.ts file:
/// <reference types="cypress" />
export { }
declare global {
namespace Cypress {
interface Chainable {
loginAs(role?: string): Chainable<any>,
isWelcomePage(): Chainable<any>,
openMenu(): Chainable<any>,
}
}
}
Similar terminal errors crop up when attempting to run component tests.