test(e2e): improve error reporting (#4931)

* cleanup

* test(e2e): improve error reporting

* lint

* lint

* better timeout messages

* fix shouldNotExist
This commit is contained in:
Elio Bischof
2023-01-04 14:38:27 +01:00
committed by GitHub
parent dc2a4ea92c
commit 35faa1b233
12 changed files with 84 additions and 225 deletions

View File

@@ -26,8 +26,11 @@ import 'cypress-wait-until';
//
interface ShouldNotExistOptions {
selector?: string;
timeout?: number;
selector: string;
timeout?: {
errMessage: string;
ms: number;
};
}
declare global {
@@ -43,7 +46,11 @@ declare global {
/**
* Custom command that waits until the selector finds zero elements.
*/
shouldNotExist(options?: ShouldNotExistOptions): Cypress.Chainable<null>;
shouldNotExist(options: ShouldNotExistOptions): Cypress.Chainable<null>;
/**
* Custom command that asserts success is printed after a change.
*/
shouldConfirmSuccess(): Cypress.Chainable<null>;
}
}
}
@@ -70,11 +77,32 @@ Cypress.Commands.add('clipboardMatches', { prevSubject: false }, (pattern: RegEx
*/
});
Cypress.Commands.add('shouldNotExist', { prevSubject: false }, (options?: ShouldNotExistOptions) => {
return cy.waitUntil(
() => {
return Cypress.$(options?.selector).length === 0;
},
{ timeout: typeof options?.timeout === 'number' ? options.timeout : 500 },
);
Cypress.Commands.add('shouldNotExist', { prevSubject: false }, (options: ShouldNotExistOptions) => {
if (!options.timeout) {
const elements = Cypress.$(options.selector);
expect(elements.text()).to.be.empty;
expect(elements.length).to.equal(0);
return null;
}
return cy
.waitUntil(
() => {
const elements = Cypress.$(options.selector);
if (!elements.length) {
return cy.wrap(true);
}
return cy.log(`elements with selector ${options.selector} and text ${elements.text()} exist`).wrap(false);
},
{
timeout: options.timeout.ms,
errorMsg: options.timeout.errMessage,
},
)
.then(() => null);
});
Cypress.Commands.add('shouldConfirmSuccess', { prevSubject: false }, () => {
cy.get('.data-e2e-message');
cy.shouldNotExist({ selector: '.data-e2e-failure' });
cy.get('.data-e2e-success');
});