Skip to content

Bug: Unable to correctly import TranslocoTestingModule.forRoot in component unit test #7475

Answered by satanTime
mlz11 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @mlz11,

you can write a test like that:

  describe('ng-mocks', () => {
    beforeEach(() => MockBuilder([
      NavbarComponent,
      TranslocoModule,
      ], CoreModule)
      .provide(getTranslocoModule().providers ?? [])
    );

    it('tests translation', () => {
      const fixture = TestBed.createComponent(NavbarComponent);
      fixture.detectChanges();

      expect(fixture.nativeElement.innerHTML).toContain('<span>Hello</span>');
    });
  });

TranslocoTestingModule uses TranslocoModule with special providers.
So to keep TranslocoModule in the test,
we just need to keep TranslocoModule and to add providers from TranslocoTestingModule.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@mlz11
Comment options

Answer selected by mlz11
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn't working
3 participants
Converted from issue

This discussion was converted from issue #7431 on November 18, 2023 13:24.