-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implicitly call expect(res).toSatisfyApiSpec() on each request and response #237
Comments
Hi @CameronHudson8, thanks for raising this :) This reminds me of #55, what do you think about that discussion? |
That discussion certainly does touch on some similar ideas. For instance, @blelump says:
I think @blelump is mistaken in the first sentence, which he acknowledges in a later post. But he is touching on the distinction I made between syntactic correctness (conformance to the OAS) and logical correctness from a functionality perspective. For requests x, the server is like a function f(x) that returns responses y. The OAS only tells you of the schema of the requests (the domain of x) and the schema of the responses (the range of y). The OAS does not tell you anything about f and how it transforms x to y. This is what integration/e2e/acceptance tests are for. I agree with @blelump's conclusion that there is not much value in calling the API with the example requests in the OAS, especially because an authentication token or pre-existing [mock] database entries will be needed for most requests. However, I think we can all agree that each request sent to the server, and each response returned from it, should conform to the API spec. You've already implemented the heavy lifting in this Hold on, I actually just googled a bit about Axios and how to intercept requests, and it already has such a feature built in. This would make the implementation far easier. It might be as simple as calling this code before the test. (As a less dry but simpler alternative, it could be called in the
|
(Background: Please forgive me if my assumptions below about
jest-openapi
's existing functionality are incorrect. I'm currently seeking a tool to confirm that my existing API tests match my OpenAPI spec. My suggestion below is based on the functionality described injest-openapi
'sREADME.md
.)At the moment, developers must call
expect(res).toSatisfyApiSpec()
on each response. However, developers might forget to call this function, and calling this function in every test is not a dry approach.However, if
jest-openapi
could intercept each request and response from a particular HTTP client, sayaxios
, then requests and responses could be validated for syntax against an OpenAPI spec implicitly and automatically. This would leave the developer free to write logical API tests ("if I delete a user, then calling GET should return 404"), while simultaneously checking request and response syntax for conformity with the OpenAPI spec in the background.The configuration for such implicit testing could be placed in the
jest.config.ts
file for test suite. The config could include the paths to the OpenAPI spec(s), the HTTP client(s) to intercept, and which domain(s) to consider for validation.This project looks really cool! Keep up the good work!
The text was updated successfully, but these errors were encountered: