Я пишу модульные тесты для компонента Angular 2 с помощью Jasmine. Я хотел бы проверить, установлено ли для моего заголовка документа определенное значение при создании экземпляра моего компонента.
Вот моя составляющая
import { Component } from '@angular/core';
import { Title } from '@angular/platform-browser';
@Component({
selector: 'cx-account',
templateUrl: 'app/account/account.component.html',
})
export class AccountComponent {
public constructor(private titleService: Title ) {
titleService.setTitle("Account");
}
}
Вот что я написал для тестирования, но это не работает. titleService.getTitle()
дает мне заголовок страницы отладчика Karma.
import { TestBed } from '@angular/core/testing';
import { Title, By } from '@angular/platform-browser';
import { AccountComponent } from './account.component';
describe('AppComponent Tests', function () {
let titleService: Title = new Title();
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AccountComponent],
providers: [ {provide: Title } ],
});
let fixture = TestBed.createComponent(AccountComponent);
});
it('Title Should be Account', () => {
expect(titleService.getTitle()).toBe('Account');
});
});
Выход кармы:
Ошибка: ожидалось, что Karma DEBUG RUNNER будет «Account».