Unit Testing
import { TranslocoTestingModule, TranslocoTestingOptions } from '@jsverse/transloco';
import en from '../assets/i18n/en.json';
import es from '../assets/i18n/es.json';
export function getTranslocoModule(options: TranslocoTestingOptions = {}) {
return TranslocoTestingModule.forRoot({
langs: { en, es },
translocoConfig: {
availableLangs: ['en', 'es'],
defaultLang: 'en',
},
preloadLangs: true,
...options,
});
}Using the module in your spec files
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [getTranslocoModule()],
declarations: [AppComponent],
}).compileComponents();
}));
it('should work', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
expect(
fixture.debugElement.query(By.css('h1')).nativeElement.innerText
).toBe('hello');
});
});Testing scopes
TypeScript Configuration
Last updated
Was this helpful?

