Skip to content

Instantly share code, notes, and snippets.

@dasDaniel
Created October 16, 2020 22:34
Show Gist options
  • Save dasDaniel/f5b817223631b156c594e2aba043bb52 to your computer and use it in GitHub Desktop.
Save dasDaniel/f5b817223631b156c594e2aba043bb52 to your computer and use it in GitHub Desktop.
cypress - check if log message was recorded
const spyConsoleLog = () => {
let logs = [];
const findLog = fragment => logs.find(message => (message + "").indexOf(fragment) >= 0);
Cypress.on("window:before:load", win => {
let clog = win.console.log;
win.console.log = (...arg) => {
logs.push(arg.join(" "));
clog.apply(console, arg);
};
});
return {
logs,
findInLogs,
};
};
///
// use in cypress...
it("checks logs", () => {
let { findInLogs } = spyConsoleLog();
cy.wait("@somestuff");
expect(findInLogs("my message chunk")).to.not.be.undefined;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment