TranslateStore not providable in test: No provider for TranslateStore
See original GitHub issueI’m submitting a … (check one with “x”)
[x] bug report => check the FAQ and search github for a similar issue or PR before submitting
[ ] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
Current behavior
After update from ng2-translate 5.0.0 (and following https://github.com/ngx-translate/core/blob/master/MIGRATION_GUIDE.md) a test fails with Error: No provider for TranslateStore! in config/spec-bundle.js (line 124915)
.
Expected/desired behavior Test should run successfully.
Reproduction of the problem Since I’m not able to run a test in a plunkr, I add the code that fails here:
describe('TestComponent', () => {
beforeEach(() => TestBed.configureTestingModule({
providers: [
BaseRequestOptions,
MockBackend,
HttpClient,
TranslateService,
{
provide: TranslateLoader,
useFactory: function (http: Http) {
return new TranslateHttpLoader(http);
},
deps: [ Http ]
},
{
provide: Http,
useFactory: function (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Http(backend, defaultOptions);
},
deps: [ MockBackend, BaseRequestOptions ]
},
{
provide: Router,
useClass: class {}
},
{
provide: ActivatedRoute,
useValue: {
params: Observable.of({id: 1})
}
}
]
}));
it('should not log ngOnInit', inject([ AbsenceComponent ], (absence: AbsenceComponent) => {
spyOn(console, 'log');
expect(console.log).not.toHaveBeenCalled();
absence.ngOnInit();
expect(console.log).not.toHaveBeenCalled();
}));
});
Additional information
So, the TranslateStore is somehow not provided, but when I try to provide it similarly to the MockBackend or the HttpClient, I import it from @ngx-translate/core, but the TranslateStore is not an exported member (https://github.com/ngx-translate/core/blob/master/index.ts, see missing export on the top) and therefore I get the error Error:(8, 10) TS2305:Module '"node_modules/@angular/compiler/index"' has no exported member 'ResourceLoader'.
And even when I manually edit the index.ts to add the missing export, I get the error Error: Invalid provider for the NgModule 'DynamicTestModule' - only instances of Provider and Type are allowed, got: [BaseRequestOptions, MockBackend, TranslateService, ?undefined?, ...] in config/spec-bundle.js (line 26501)
.
Please tell us about your environment:
-
ngx-translate version: @ngx-translate/core: 6.0.1 @ngx-translate/http-loader: 0.0.3
-
Angular version: 2.4.10
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:12
Top GitHub Comments
Possible workaround:
Same issue. require fix, because i have to add
import { TranslateStore } from "@ngx-translate/core/src/translate.store";
andproviders: [ TranslateStore ],
in AppModule. I also use forChild in SharedModule