You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a solution for verifying that no request(s) to certain endpoint(s) are made within a specific timeout after performing a certain action.
The solution works as expected and fulfills our requirements flawlessly.
However, we noticed that the return type of cy.get() is defined as JQuery<HTMLElement>.
Given the provided example, it seems that the return type of the get command should not always be JQuery<HTMLElement>, but also support intercepted requests and arrays of intercepted requests.
Does anyone know why, in the Cypress API, the return type of the get command is always set to JQuery<HTMLElement>, even though use cases like the one mentioned below are possible?
Is this aspect documented or discussed anywhere?
In cypress/commands.ts file. Notice that in cy.get(${intercept.alias}.all).then(calls => { the we work with calls that are not the HTML element but intercepted requests.
Cypress.Commands.add("failIfEndpointIsCalled", (endpointAlias, timeout, triggerFunction) => {
const aliases = Array.isArray(endpointAlias) ? endpointAlias : [endpointAlias];
const intercepts = aliases.map(alias => {
return {alias, interceptedTimesBefore: 0};
});
intercepts.forEach(intercept => {
cy.get(`${intercept.alias}.all`).then(calls => {
intercepts;
intercept.interceptedTimesBefore = calls.length;
});
});
triggerFunction();
cy.wait(timeout).then(() => {
intercepts.forEach(intercept => {
cy.get(`${intercept.alias}.all`, {timeout: 0})
.should("have.length", intercept.interceptedTimesBefore, `Number of new requests to '${intercept.alias}' should be 0. `
+ `Total number of intercepted requests is expected to be ${intercept.interceptedTimesBefore}`);
});
});
})
Usage example in spec file. The test would fail if in 10 seconds after the click on the button there will be requests sent to endpoint1 or endpoint2. failIfEndpointIsCalled command will accept a single intercepted request alias as an argument or an array of intercepted aliases.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We have a solution for verifying that no request(s) to certain endpoint(s) are made within a specific timeout after performing a certain action.
The solution works as expected and fulfills our requirements flawlessly.
However, we noticed that the return type of
cy.get()
is defined asJQuery<HTMLElement>
.Given the provided example, it seems that the return type of the get command should not always be
JQuery<HTMLElement>
, but also support intercepted requests and arrays of intercepted requests.Does anyone know why, in the Cypress API, the return type of the get command is always set to
JQuery<HTMLElement>
, even though use cases like the one mentioned below are possible?Is this aspect documented or discussed anywhere?
In
cypress/commands.ts
file. Notice that incy.get(${intercept.alias}.all).then(calls => {
the we work withcalls
that are not the HTML element but intercepted requests.Usage example in spec file. The test would fail if in 10 seconds after the click on the button there will be requests sent to endpoint1 or endpoint2.
failIfEndpointIsCalled
command will accept a single intercepted request alias as an argument or an array of intercepted aliases.in cypress/types/index.d.ts file
Beta Was this translation helpful? Give feedback.
All reactions