DEV Community

Discussion on: Cypress - End to End Testing Framework

Collapse
 
jaredmeakin profile image
Jared Meakin

For those using cypress for E2E testing do you simply mock all your API calls?

Has anyone found a testing strategy similar to how RoR does it? Specifically, a test database that gets reset after every run?

I just hate mocking every single endpoint in JS projects that heavily rely on multiple microservices. It becomes an exercise in tedium.

Collapse
 
dmitry profile image
Dmitry Polushkin • Edited

In rails you normally can use FactoryBot through middleware on server side and commands to clean/setup specs in cypress. Doing calls to your real app makes everything updated, no need to write mocks, especially it can be a problem for websocket apps (not enough tools for now to mock websocket). So in other words you are doing integration testing, which is higher level, with easiness of unit testing - which is absolutely great and fast enough.

One of the solutions: github.com/shakacode/cypress-on-rails

Collapse
 
yucer profile image
yucer

I do also like to test the middle-ware directly.

It forces you to keep all the logic away from client code.

If someone implements part of the business logic with a javascript in the browser ... that is not secure and might not end well in some cases.

My opinion is that the browser code should be used only for usability requirements. And those use cases need also test, so +1 for cypress for helping on that.

Nevertheless the middleware / APIs should be tested directly, also for preventing those invalid input cases that the interface might never send, but that might break everything.

Collapse
 
yucer profile image
yucer

Do you define all your interfaces by hand ?

In the case of REST endpoints, the same code generator (Ex: openapi-generator) that generate the endpoints from the API specs (Ex: OpenAPI) might generate the client library with basic unit tests.