Skip to content

Instantly share code, notes, and snippets.

@filiphric
Created March 9, 2020 15:49
Show Gist options
  • Select an option

  • Save filiphric/fcd1aa541a85cd0c5c70929b10b58403 to your computer and use it in GitHub Desktop.

Select an option

Save filiphric/fcd1aa541a85cd0c5c70929b10b58403 to your computer and use it in GitHub Desktop.
beforeEach( function() {
window.logCalls = 1;
window.testFlow = [];
});
Cypress.Commands.overwrite('log', (originalFn, message) => {
Cypress.log({
displayName: `--- ${window.logCalls}. ${message} ---`,
name: `--- ${window.logCalls}. ${message} ---`,
message: ''
});
window.testFlow.push(`${window.logCalls}. ${message}`);
window.logCalls++;
});
Cypress.on('fail', (error) => {
throw new Error(error + '\n\nTest flow:\n' + window.testFlow.join('\n'));
});
@clasicul
Copy link
Copy Markdown

clasicul commented Apr 2, 2020

@filiphric
Copy link
Copy Markdown
Author

Nice! 👍

@kamilnecas
Copy link
Copy Markdown

It looks like this is working in Typescript as well. But for some reason "logCalls" and "testFlow" are getting highlighted for not existing property for window. Any recommended solution how to avoid highlighting?

I have found it is feasible to use "any" command but it is a bit dirty according to feedback.

@filiphric
Copy link
Copy Markdown
Author

I added these to my support/index.js as well:

declare global {
  interface Window {
    logCalls: number;
    testFlow: string[];
  }
}

@kamilnecas
Copy link
Copy Markdown

Perfect! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment