Написание модульных тестов для Angular i18n
Я использую Jasmine / Karma для модульного тестирования кода с использованием переводов Angular i18n (с локализацией). В настоящее время возникает следующая ошибка:
AssetReplicateComponent > executable models > should have a title "Replicate Asset"
Expected ' _replicate_model_title ' to contain 'Replicate Asset'.
Я настраиваю тест следующим образом:
const translations = require('raw-loader!src/i18n/messages.en.xlf').default;
beforeEach(waitForAsync(() => {
class DummyModelDetailsComponent {}
...
TestBed.configureTestingModule({
...
providers: [
...
{ provide: TRANSLATIONS, useValue: translations },
{ provide: TRANSLATIONS_FORMAT, useValue: 'en' },
{ provide: LOCALE_ID, useValue: 'en' }
]
})
.compileComponents();
Фактический тест:
it('should have a title "Replicate Asset"', () => {
const title = fixture.debugElement.query(By.css('[data-cy=replicateModelTitle]'));
expect(title.nativeElement.textContent).toContain('Replicate Asset');
});
Соответствующий код компонента:
<h4 data-cy="replicateModelTitle" class="d-inline-block text-secondary pr-3 mr-3 mb-2 border-right" i18n="@@replicate_model_title">
_replicate_model_title
</h4>
Файл перевода:
<trans-unit id="replicate_model_title" datatype="html">
<source> _replicate_model_title </source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/assets/components/asset-replicate/asset-replicate.component.html</context>
<context context-type="linenumber">5,6</context>
</context-group>
</trans-unit>
Не похоже, что перевод вообще был сделан при модульном тестировании. Что мне не хватает?