I want to clean a database before running my test cases and I'm just having issues with it running. It just times out and I don't understand - hopefully you can help me :)
In the test case I have the following code block:
beforeEach(() => {
cy.task("cleanUpDB", {
sql:"UPDATE SQL GOES HERE"
})
This then goes to my cypress.config file and the following is executed:
on("task", {
cleanUpDB({ theQuery }) {
return new Promise(async(resolve, reject) => {
try{
await sql.connect(DBConfig)
const result = await sql.query(theQuery);
console.log(result)
return resolve(result);
}
catch (err) {
// ... error checks
}
}
)
}
})
You must use the same property name sql
inside the task
beforeEach(() => {
cy.task("cleanUpDB", {
sql:"UPDATE SQL GOES HERE"
})
on("task", {
cleanUpDB({ sql }) { // since you wrap the parameter
... // you must use the property name sql
or just pass in the query directly
beforeEach(() => {
cy.task("cleanUpDB", "UPDATE SQL GOES HERE")
on("task", {
cleanUpDB(theQuery) { // name can be anything
...