我正在使用Jasmine编写Angular 2组件的单元测试.我想测试在我的组件实例化时我的文档标题是否已设置为特定值.
这是我的组件
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");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我为测试而编写的,但它不起作用.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 } ],
}); …Run Code Online (Sandbox Code Playgroud)