thousands-angle-35788
11/23/2022, 11:01 PMexport function postRequest() {
const endpoint = '/some/path';
const url = `http://example.com${endpoint}`;
const alias = 'postRequest';
const params = {
method: 'POST',
url: url,
body: createJsonBody(),
};
cy.intercept(url).as(alias);
cy.request(params);
cy.wait(`@${alias}`);
}
I would expect this variation to work, but it doesn't intercept this request
export function postRequest() {
const endpoint = '/some/path';
const url = `http://example.com${endpoint}`;
const alias = 'postRequest';
const params = {
method: 'POST',
url: url,
body: createJsonBody(),
};
cy.intercept({ method: 'POST', url: url }).as(alias);
cy.request(params);
cy.wait(`@${alias}`);
}
I have also tried these variations, they all do not intercept the request:
cy.intercept('POST', url).as(alias);
cy.intercept('POST', endpoint).as(alias);
cy.intercept('POST', `**${endpoint}`).as(alias);
cy.intercept({ method: 'POST', path: endpoint}).as(alias);
cy.intercept({ method: 'POST', path: url}).as(alias);
cy.intercept({ method: 'POST', path: `**${endpoint}`}).as(alias);
cy.intercept(url, (req) => {
if (req.method === 'POST') {
req.alias = alias;
}
});
Also tried with a lowercase alias, since I read somewhere that was a known issue.
This GET intercept works fine (but ofcourse only on the GET):
cy.intercept('GET', endpoint).as(alias);