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

InjectorService invoke method doesn't call $onInit #504

Closed
avivVonage opened this issue Jan 7, 2019 · 3 comments
Closed

InjectorService invoke method doesn't call $onInit #504

avivVonage opened this issue Jan 7, 2019 · 3 comments
Labels

Comments

@avivVonage
Copy link

avivVonage commented Jan 7, 2019

If I write a test like this:

test('testName', inject([MyService, Done], async(myService: MyService, done: Done) => {
  ...
}

The $onInit method of MyService is called.

But if I want to mock the services that MyService uses I want to write it like this:

test('testName', inject([InjectorService, Done], async(injectorService: InjectorService, done: Done) => {
  ...
  const locals = new Map();
  locals.set(OtherService, myMock);
  const myService = injectorService.invoke<MyService>(MyService, locals);
  ...
}

Unfortunately, now the $onInit method of MyService is not called.

I can call this method by myself, but why isn't it done inside the invoke method?

@Romakita
Copy link
Collaborator

Romakita commented Jan 9, 2019

Hello @avivVonage
Yes isn't normal. I already works on the fix. After the new release, your unit test should be written like that:

before(TestContext.create)
after(TestContext.reset)
test('testName', async () => {
  const myService = await TestContext.invoke<MyService>(MyService, [
      provide: OtherService, use: myMock
  ]);
  ...
}

async / await is only required if the $onInit method return a promise. Otherwise, isn't required.

I'll tell you when the fix is released
See you,
Romain

@Romakita
Copy link
Collaborator

Romakita commented Jan 9, 2019

Release in progress

@Romakita
Copy link
Collaborator

Romakita commented Jan 9, 2019

🎉 This issue has been resolved in version 5.0.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants