core: [Testing] [Angular-cli] Can't resolve all parameters when TranslateService is required in injection
I’m submitting a … (check one with “x”)
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
Current behavior I can’t run basic karma+Jasmine tests using angular-cli configuration. I get the following error:
Error: Can’t resolve all parameters for I18nToolsService: (?).
And I18nToolsService
’s constructor is:
constructor(private translator: TranslateService) {
}
My test file is a simple test file :
describe('I18nToolsService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot()
],
providers: [
I18nToolsService
]
});
});
it('should be created', inject([I18nToolsService], (service: I18nToolsService) => {
expect(service).toBeTruthy();
}));
});
Expected/desired behavior The tests should run fine, with no errors at startup.
Please tell us about your environment:
-
ngx-translate version: 8.0.0
-
Angular version: 4.3.6
-
Karma version: 1.4.1
-
Jasmine version: 2.5.2
-
Angular cli version: 1.4.0
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 2
- Comments: 15
Are you importing the es7 reflect polyfill? If not, you could try if adding the following line to the polyfills.ts fixes your issues:
and you might also want to check you tsconfig.json file for
"emitDecoratorMetadata": true,
I also had the same problem. I managed to solve by putting in
tsconfig.spec.json
from the root of the project the optionemitDecoratorMetada
as true.My
tsconfig.spec.json
Any updates on that? I really need to be able to test my app and at the moment this is the only thing I’m stuck with.
I faced the same problem and fixed it this way.
Same here, some input would be nice since testing is an important part of any serious app; please provide some documentation on testing, thanks !