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
Passing Dynamic Mock to Promise Resolve #66
Comments
Passing a mock object to Promise.resolve doesn't seem to make much sense. I assume your intention was to resolve it like this:
Let me know if your test still fails after making the change above. |
Hi @florinn, Can you explain why mocks yielding Promises to other mocks (as @jdbriaris illustrates above) "doesn't make much sense"? It seems a perfectly reasonable scenario to me -- indeed our team requires it -- and it is still broken in Regards, --- a/test/spec/Mock.test.ts
+++ b/test/spec/Mock.test.ts
@@ -1401,7 +1401,7 @@ describe("Mock", () => {
mockModel.setup(x => x.someProperty).returns(() => "info");
const mockMyService = TypeMoq.Mock.ofType<MyService>();
- mockMyService.setup(x => x.doStuff()).returns(() => Promise.resolve(mockModel.object.someProperty))
+ mockMyService.setup(x => x.doStuff()).returns(() => Promise.resolve(mockModel.object));
const myClass = new MyClass(mockMyService.object); |
If your test scenario requires passing a mock object to
This is due to a limitation of the underlying technology. For more information see issue #70 |
I've defined
MyService
as followsand
MyClass
that consumesMyService
asIn addition, I have an interface
MyModel
defined asNow I want to write a test such that I can mock
MyService
using TypeMoq. So I did the followingHowever, the
Promise.resolve(mockModel.object)
never seems to resolve when supplied with the TypeMoq mock as shown above, i.e., I don't get "Promise resolved!" (or "Promise rejected!") printed to the console and the jasmine test times out.If I replace
Promise.resolve(mockModel.object)
withPromise.resolve({ someProperty: 'info'})
, i.e.,then the test works (I get "Promise resolved!" printed to the console). Why doesn't
Promise.resolve()
resolve when supplied with a TypeMoq mock? Is this a limitation of dynamic mocking?The text was updated successfully, but these errors were encountered: