Snippets
What and Why
Why
Cypress does not support mocking an endpoint based on the request body for example a search endpoint that returns different results based on the query passed. Also not supported would be a counter endpoint as the mock would always return the same result.
What
This supports doing request based responses or sequence based responses;
Usage 1 - request body matching
this will set a watcher on the url and return 'here' but only if the body validate fn returns true when passed the request body
cy.route('POST', '**/v1/lookup/**', body => body.type === 'TypeA', 'here');
cy.route('POST', '**/v1/lookup/**', body => body.type === 'TypeB', 'there');
cy.visit('**/some/url/path');
Usage 1 - sequential results
this will watch the url and will reply with here1 on the first ajax, here2 on the second, here3 on the third and is variadic so it will support as many responses as you need
cy.route('POST', '**/v1/lookup/**', 'here1', 'here2', 'here3');
cy.route('GET', '**/some/counter/**', ...range(1, 10000)) // counter with support up to 10,000
cy.visit('**/some/url/path');
Instalation
you must have a url that will echo back whatever body is sent to it and export that as ECHO_BACK_URL which is imported by bodyRouter.ts
copy the included files to cypress/utils
in cypress/support/command.ts
import the bodyBodyRouter.ts file
import '../utils/improved-router';
Comments (1)
You can clone a snippet to your computer for local editing. Learn more.
https://ko-fi.com/agario535395282
https://www.crunchyroll.com/user/Agario244
https://disqus.com/by/disqus_XTOlCAa04j/
https://www.minds.com/agario463/about
https://onedio.com/profil/agario637/
https://www.behance.net/agarioagario
https://qiita.com/Agario433
https://tr.gravatar.com/agario5534
https://www.instructables.com/member/Agario5353/?publicPreview=true
https://dribbble.com/Agario6457
https://www.magcloud.com/user/agario543
https://www.goodreads.com/user/show/149078206-agario
https://agario4665.livejournal.com/profile
https://www.dead.net/member/agario57546
https://penzu.com/p/5baa67e3
https://www.instapaper.com/read/1491741037
https://qr.ae/pGLSjQ
https://qr.ae/pGLSQN
https://www.goodreads.com/user/show/149079025-agario-unblocked
https://tr.gravatar.com/agariounblocked443