Open ditman opened 2 months ago
Summary: The toJS
method cannot be used on a function that returns Future<Never>
because it throws an exception and never completes. The user is looking for a more elegant way to mock a function that throws an exception.
Good bot @dart-github-bot !
I think the conflict is really Never
and not Future<Never>
looking at the static type.
At some point we discussed supporting Never
in the allowed types but decided against it for some reason I don't remember. Maybe because the exception is not really a JS value? That's an insufficient reason if so, and we should support this.
A cleaner workaround may be to cast the function to a valid type e.g.
((() => throw 'done') as void Function()).toJS;
We've been porting some old test code to a newer style, and I was trying to "mock" a function that ends up throwing:
However the compiler complains that it doesn't like
Never
:So I need to end up doing:
Is there a more graceful way to handle something like this?