janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
241 stars 58 forks source link

Unit tests rely on a third-party service to work #64

Open zhevron opened 6 years ago

zhevron commented 6 years ago

Currently, the unit tests rely on the "Trippin" example service. Which means that the unit tests actually rely on this API to work. I've seen multiple examples where the library produces the correct request, but the API fails with HTTP status code 500, causing the tests to fail anyway.

IMO, it would be better to simply test the request object before it goes out to any server. Since the project currently uses Jasmine for testing, one possibility is to use jasmine-ajax to intercept the requests and run tests on them.

This way, the URL, method, data, etc can be tested without actually relying on a real API to respond. This also allows tests to be run in a offline-only scenario when developing.

Thoughts? As long as the tests enforce the OData protocol spec, it should be a better approach and allow for corner case testing without the Trippin service implementing that endpoint.

janhommes commented 6 years ago

I like the idea. But it is not an easy task. The test-mocks must follow the specs and therefore somebody has to invest time to set-up the mocks correctly.

Jasmin-Ajax looks like a good library to do that and this will allow us to test all internal functions until the initialized request. Another idea is to fake any request which is going to base.get(), base.post() (etc.), but this will only allow us to test the public available functions.