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
Mocking support #531
Comments
|
@mcollina what can we do to help here, do you have an idea on how to do the magic? In my understanding undici is not using nodejs HTTP module under the hood, so we need to intercept the request in another way. |
|
Send a PR :). I would recommend to add a |
|
What do you mean by adding a In my understanding, we want something that intercepts the undici network calls and returns a mocked response. const { MockClient } = require("undici");
const client = new MockClient("https://www.nodejs.org");
client.intercept({
path: "/",
method: "GET",
}).reply(200, { "foo": "bar"});Wherever in you code you use undici to perform a GET https://www.nodejs.org/ the result is Still, I don't know how to intercept the requests |
|
The API you are sketching is correct!
Neither would I! You might have to overload a few (or all) of the APIs in |
According to docs, it would be a matter of overwrite just only client.dispatch(). |
|
I'm very happy to work on an implementation based on @adamovittorio's suggestion if that's okay with everyone? If so, it'll include the |
|
Go for it @jonnydgreen! Open a draft PR as early as possible so when can provide iterative feedback. |
|
Awesome! Will do, I'll submit a draft PR for initial feedback as soon as possible! :) |
|
If I may add, would it not be better to put the mocking in a separate package? Many users will not be using the mock functionality, and it is not integral to undici's function, so perhaps it should be put in an In regards to undici not using HTTP under the hood, I believe intercepting the requests at the |
|
+1 to the independent package. Regarding mocking |
|
@piranna Gotcha, it was more of a concept inspired by the old Thank you for the +1 though. It seems like the dev team are keen to get it released first and then look into separating the packages later on, so hopefully, this will be done soon. |
Hey Matteo, I'm helping maintain |
AFAIK |
That is exactly why. undici isn't a request library like others. It is intended to be an alternative to |
|
@mcollina can we close this? |
|
Yes it's done |
@mcollina, can you please share here a link, or an example of how to mock I'm sure many people will end up on this issue, and also wonder how to do that. Thanks. |
I think it would be awesome if we had mocking support, similar to nock.
The text was updated successfully, but these errors were encountered: