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
fix(upgrade): add try/catch when downgrading injectables #38671
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,16 @@ describe('downgradeInjectable', () => { | |
expect(factory(mockNg1Injector)).toEqual('service value'); | ||
expect(mockNg2Injector.get).toHaveBeenCalledWith('someToken'); | ||
}); | ||
|
||
it('should throw an error if injector is undefined', () => { | ||
const factory = downgradeInjectable('someToken', 'someModule'); | ||
expect(factory).toEqual(jasmine.any(Function)); | ||
expect((factory as any).$inject).toEqual([$INJECTOR]); | ||
|
||
const {mockNg1Injector} = setupMockInjectors('someModule'); | ||
const error = | ||
'Trying to get the Angular injector before bootstrapping the corresponding Angular module. Injector name: someToken'; | ||
mockNg1Injector.get.and.throwError(error); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this test would pass without the fix, since you are specifying the new error message in the mock error that is thrown, yes? Perhaps make the mock error that is thrown match the old error message - i.e. |
||
expect(() => factory(mockNg1Injector)).toThrowError(error); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a couple of issues with this error:
token
) and keep the original error's message (which has more info on the actual error).token
is not the name of the injector. It is the identifier of the injectable.I would suggest something like:
Or I would even go for: