question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TranslateStore not providable in test: No provider for TranslateStore

See original GitHub issue

I’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:

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12

github_iconTop GitHub Comments

76reactions
pumanocommented, Jun 14, 2017

Possible workaround:

import { TranslateModule, TranslateService, TranslateLoader, TranslateFakeLoader } from '@ngx-translate/core';
....

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        TranslateModule.forRoot({
          loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
        })
      ],
      ...
18reactions
RostyslavAHcommented, Mar 28, 2017

Same issue. require fix, because i have to add import { TranslateStore } from "@ngx-translate/core/src/translate.store"; and providers: [ TranslateStore ], in AppModule. I also use forChild in SharedModule

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: No provider for TranslateStore - Stack Overflow
Try this: import {TranslateFakeLoader,TranslateLoader,TranslateModule,TranslateService } from '@ngx-translate/core'; TestBed.
Read more >
TranslateStore not providable in test - Bountysource
a test fails with Error: No provider for TranslateStore! in config/spec-bundle. js (line 124915) .
Read more >
Angular testing-->No provider for TranslateStore!
Angular testing-->No provider for TranslateStore! ; 1. import {TranslateFakeLoader,TranslateLoader,TranslateModule,TranslateService } from '@ngx-translate/core';.
Read more >
Nullinjectorerror: No Provider For Translate Service - ADocLib
TranslateStore not providable in test : No provider for TranslateStore # [x] bug report > check the FAQ and search github for a...
Read more >
Top 5 @ngx-translate/core Code Examples - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... import { CoreBlockDelegate } from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found