2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2019-08-22 19:16:25 -07:00
|
|
|
import {ɵgetDOM as getDOM} from '@angular/common';
|
2016-09-14 22:21:23 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {TestBed} from '@angular/core/testing';
|
|
|
|
import {BrowserModule, Title} from '@angular/platform-browser';
|
2017-03-02 12:12:46 -08:00
|
|
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
2015-03-09 17:39:18 +01:00
|
|
|
|
2017-12-16 14:42:55 -08:00
|
|
|
{
|
2015-03-09 17:39:18 +01:00
|
|
|
describe('title service', () => {
|
2017-08-08 02:17:40 -07:00
|
|
|
let doc: Document;
|
|
|
|
let initialTitle: string;
|
|
|
|
let titleService: Title;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
doc = getDOM().createHtmlDocument();
|
2019-08-30 11:31:24 -07:00
|
|
|
initialTitle = doc.title;
|
2017-08-08 02:17:40 -07:00
|
|
|
titleService = new Title(doc);
|
|
|
|
});
|
2015-03-09 17:39:18 +01:00
|
|
|
|
2019-08-30 11:31:24 -07:00
|
|
|
afterEach(() => { doc.title = initialTitle; });
|
2015-03-09 17:39:18 +01:00
|
|
|
|
2015-05-27 13:48:24 -07:00
|
|
|
it('should allow reading initial title',
|
|
|
|
() => { expect(titleService.getTitle()).toEqual(initialTitle); });
|
2015-03-09 17:39:18 +01:00
|
|
|
|
|
|
|
it('should set a title on the injected document', () => {
|
|
|
|
titleService.setTitle('test title');
|
2019-08-30 11:31:24 -07:00
|
|
|
expect(doc.title).toEqual('test title');
|
2015-03-09 17:39:18 +01:00
|
|
|
expect(titleService.getTitle()).toEqual('test title');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should reset title to empty string if title not provided', () => {
|
2017-03-24 09:59:41 -07:00
|
|
|
titleService.setTitle(null !);
|
2019-08-30 11:31:24 -07:00
|
|
|
expect(doc.title).toEqual('');
|
2015-03-09 17:39:18 +01:00
|
|
|
});
|
2016-09-14 22:21:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('integration test', () => {
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
class DependsOnTitle {
|
|
|
|
constructor(public title: Title) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
imports: [BrowserModule],
|
|
|
|
providers: [DependsOnTitle],
|
|
|
|
});
|
|
|
|
});
|
2015-03-09 17:39:18 +01:00
|
|
|
|
2016-09-14 22:21:23 +02:00
|
|
|
it('should inject Title service when using BrowserModule',
|
2019-08-28 16:22:36 -07:00
|
|
|
() => { expect(TestBed.inject(DependsOnTitle).title).toBeAnInstanceOf(Title); });
|
2015-03-09 17:39:18 +01:00
|
|
|
});
|
|
|
|
}
|