Created
October 16, 2020 22:34
-
-
Save dasDaniel/f5b817223631b156c594e2aba043bb52 to your computer and use it in GitHub Desktop.
cypress - check if log message was recorded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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