Skip to content
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

Is there a way to have MockServerCallback's server parameter be strongly typed? #130

Open
Desync-o-tron opened this issue May 23, 2022 · 3 comments
Assignees

Comments

@Desync-o-tron
Copy link

I will write test code like this:
dioAdapter.onPost("some_route", (server) => server.reply(...), data: Matchers.any);
I am very much bugged that I do not know the type of 'server'. Moreover, I don't really know what to pass to server.reply()!

What I've tried:
I've looked through the relevant docs, but I see no page on MockServerCallback. I've looked into the code and tried declaring the type of the callback that I pass into onPost(), but my linter won't allow me.

@theiskaa
Copy link
Contributor

theiskaa commented Jun 17, 2022

Its type is basically dynamic. And basing on exact type is not allowed yet.
Would you like to have kinda feature?

@theiskaa theiskaa self-assigned this Jun 17, 2022
@orevial
Copy link
Contributor

orevial commented Jun 9, 2023

I think the problem is not that the callback is not strongly typed because it is (it is defined as a typedef of type void Function(MockServer server);), but rather than MockServerCallback and MockServer types are not exposed by the package.

In my case I would like to reuse the MockServerCallback function between multiple adapter methods but I can't because of types not being exposed.

Example of what I would like to do:

adapter.onGet('/some/route', replyCallback);
adapter.onPost('/some/route', replyCallback);
adapter.onPut('/some/route', replyCallback);

void replyCallback(MockServer server) {
    server.reply(200, {'message': 'success'});
}

Right now the compiler complains about MockServer that is undefined because it cannot see it.

Could we expose it ? I can propose a PR

@LukaGiorgadze
Copy link
Member

I think the problem is not that the callback is not strongly typed because it is (it is defined as a typedef of type void Function(MockServer server);), but rather than MockServerCallback and MockServer types are not exposed by the package.

In my case I would like to reuse the MockServerCallback function between multiple adapter methods but I can't because of types not being exposed.

Example of what I would like to do:

adapter.onGet('/some/route', replyCallback);
adapter.onPost('/some/route', replyCallback);
adapter.onPut('/some/route', replyCallback);

void replyCallback(MockServer server) {
    server.reply(200, {'message': 'success'});
}

Right now the compiler complains about MockServer that is undefined because it cannot see it.

Could we expose it ? I can propose a PR

@theiskaa thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants