Reputation: 1
i am using ng-mocks and want to test an angular component which uses translations. i would love to use the .withTranslation to respect the language file structure. but yet i've not found a way to use the TranslateTestingModule and need to mock the TranslateService instead like:
beforeEach(() =>
MockBuilder(MyDialogComponent)
.mock(TranslateService, { instant: (key) =>
key.includes('rejected') ? 'No!': 'OK!'
})
.provide(MyDialogService)
.then(() => service = TestBed.inject(MyDialogService))
);
has anybody an idea how to get it?
I've tried to use the mock builder instead like:
const ngModule = MockBuilder(BonusDialogComponent)
.provide(BonusDialogService)
.build();
ngModule.imports = [TranslateTestingModule.withTranslations(LANGUAGE, TRANSLATIONS)];
service = TestBed.inject(BonusDialogService);
return TestBed.configureTestingModule(ngModule).compileComponents();
but only got an No Provider for TranslateService
Upvotes: 0
Views: 66
Reputation: 1
thank you! i found an other suitable solution:
beforeEach(() => MockBuilder([
MyDialogComponent,
TranslateModule,
TranslateTestingModule.withTranslations('de', de),
])
.provide(BonusDialogService)
.then(() => service = TestBed.inject(MyDialogService))
);
its the same with routes:
https://ng-mocks.sudo.eu/guides/route
Upvotes: 0