Please some help.
I have a debounced handleChange function to an input. The debounced function is:
const useDebounce = (func, timeout = 500) => {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { func.apply(this, args); }, timeout);
};
}
export default useDebounce
And handler is:
const handleChange = (e) => {
onData({ name: e.target.name, value: e.target.value });
};
const debouncedHandleChange = useDebounce((e) => handleChange(e), 700);
The debounce function is fetching data from an API. If i use the browser, it's work fine.
Note: I used in the same code the debounce function of lodash and it's ok, but I should use the useDebounce function.
The cypress test is:
describe('Testing autoload PreForm information [Desktop]', () => {
beforeEach(() => {
cy.loadingCucaCorpContact();
cy.visit('/');
cy.setViewportXL();
});
it('should display autoloaded information', () => {
cy.findAllByText('Despacho y retiro').click();
cy.findAllByText('No ha llegado mi producto').click();
cy.get('[data-cy=inputrutNotReceived]').type('11111111-1');
cy.get('[data-cy=inputorderIdNotReceived]').type('777777777');
cy.contains(
'Lo sentimos, estamos presentando algunas dificultades, vuelve a intentarlo dentro de un momento',
{ timeout: 5000 }
);
});
});
Well, the test is not succeded because isn't calling the API. I used examples like:
cy.wait(6000)
...
cy.clock()
cy.tick(500)
...
cy.get('[data-cy=inputorderIdNotReceived]').type('777777777').trigger('change);
... and still doesn't work
Any idea?
Best regards.