I am trying to translate a page using the German and English variants using ng2-translate.
navbar.component.html
<div id="sidebar-wrapper"> <div class="side-wrap-div"> <div class="list-group sidebar-nav"> <li class="list-group-item borderBottomMenu active" > <a href="#">{{ 'PAGE.GENERAL' | translate}}</a> <span class="marker-logo"></span> <span class="logo allgemein-logo-click" ></span> </li> </div> </div> </div>
navbar.component.spec.ts
import { TestBed, ComponentFixture, async } from "@angular/core/testing"; import { DebugElement } from "@angular/core"; import { By } from "@angular/platform-browser"; import { SidenavComponent } from "../sidenav/sidenav.component"; import {TranslateService, TranslateModule} from "ng2-translate"; class TranslateServiceMock { private lang: string; public getTranslation() : string { return this.lang; } } describe('Navbar Component Test', () => { let comp: SidenavComponent; let fixture: ComponentFixture<SidenavComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ SidenavComponent ],
Translation happens and {{'PAGE.GENERAL' | translate}} translates correctly. Therefore, in the getTranslation () specification, TranslateService retrieves data from Json files (en.json and de.json). I am mocking this service in TranslateServiceMock. How to check it? Any help?
unit-testing angular karma-jasmine
Protagonist
source share