Closed ceoworks closed 3 days ago
Hello @ceoworks
In that scenario, you should use the string-based injection token, which for you is the enum (DI
), instead of using the class as the identifier (look here)
const { unit, unitRef } = await TestBed.sociable(UserService).expose<UserApi>(DI.UserApi).compile();
Having said that, I've now noticed a bug with the identifier in the expose
method. I'll be opening a new issue for this.
In the meantime, please use this workaround:
const { unit, unitRef } = await TestBed.sociable(UserService).expose<UserApi>(DI.UserApi as never).compile();
Please let me know if it worked for you :) CC: @qballer
Hi @omermorad, after reading more docs and trying your fixes, it seems like I still have the issues.
I changed the code to the following and got the following error:
My goal is to be able to get HttpService and I still can not 😞 I updated the code in the repository so you can easily reproduce it 🙏
Please refer to this section in the docs
You cannot retrieve an exposed class from the unitRef using .get() after calling .expose().
This limitation is by design. The purpose of .expose() is to make the class a real, non-mocked
dependency within the test context, making it part of the "system under test."
In the example given above, this is what you are doing AFAICT.
Closing this one @ceoworks
@qballer @omermorad you are correct, I was trying to get the exposed module, which was leading to an error. However, after I updated the code to not getting the exposed ref, it still gives me an error:
Hi @omermorad, after reading more docs and trying your fixes, it seems like I still have the issues.
I changed the code to the following and got the following error:
So I am still not able to get mocked HttpService 😞 I carefully checked the code and I can't find any more the differences between my code and documentation, I kindly ask your help here 🙏
Is there an existing issue for this?
Current behavior
I'm using suits with inversify and jest. I reproduced the class hierarchy from the docs and while it works fine with Inversify, it seems to not locating the injected services when using both inversify and jest:
Please check Readme for more details.
Minimum reproduction code
https://github.com/ceoworks/suits-inversify-bug
Steps to reproduce
yarn install
yarn jest
Expected behavior
I should not have the error.
Suites version
3.0.0
Node.js version
20.16.0
In which operating systems have you tested?
Other
No response