busy-agency-3812
03/18/2023, 12:02 AMconst getDivisionBody = () => {
return {
data: {
division: {
utilitiesConfig: {
electric: false,
},
__typename: 'Division',
},
},
};
};
My fixture had electric set to false but I want to be able to create a function which can toggle the value to false or true. First, I wanted to make sure the intercept could take this variable before I modify it.
so I did this:
cy.intercept('POST', '/graphql', (req) => {
if (req.body.operationName === 'getDivision') {
req.reply(`${getDivisionBody}`);
}
});
Now my cypress is able to see the variable but it returns this, including the function part
function () {
return {
data: {
division: {
utilitiesConfig: {
electric: false,
},
__typename: 'Division',
},
},
};
}
And if I do
cy.intercept('POST', '/graphql', (req) => {
if (req.body.operationName === 'getDivision') {
req.reply(getDivisionBody);
}
});`gray-kilobyte-89541
03/18/2023, 1:41 AMgetDivisionBody is a function so you want to do cy.reply(getDivisionBody())