From f3937f2d536468c3ce27cb0b83d5dad8f764b234 Mon Sep 17 00:00:00 2001 From: cipchk Date: Tue, 2 Jan 2024 16:35:35 +0800 Subject: [PATCH] chore: add title test --- .../src/services/title/title.service.spec.ts | 62 +++++++++++++------ 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/packages/theme/src/services/title/title.service.spec.ts b/packages/theme/src/services/title/title.service.spec.ts index 33f39e595b..66802f0a6b 100644 --- a/packages/theme/src/services/title/title.service.spec.ts +++ b/packages/theme/src/services/title/title.service.spec.ts @@ -25,25 +25,6 @@ describe('Service: Title', () => { } } - class TestDocument { - querySelector(): NzSafeAny { - return { - childNodes: [], - firstChild: { - textContent: 'a' - } - }; - } - querySelectorAll(): NzSafeAny { - return { - childNodes: [], - firstChild: { - textContent: 'a' - } - }; - } - } - let title: TestTitleService; let srv: TitleService; let i18n: AlainI18NService; @@ -227,11 +208,54 @@ describe('Service: Title', () => { describe('should be hava title via element', () => { it('with element', fakeAsync(() => { + class TestDocument { + querySelector(): NzSafeAny { + return { + childNodes: [], + firstChild: { + textContent: 'a' + } + }; + } + querySelectorAll(): NzSafeAny { + return { + childNodes: [], + firstChild: { + textContent: 'a' + } + }; + } + } genModule([{ provide: DOCUMENT, useClass: TestDocument }]); srv.setTitle(); tick(srv.DELAY_TIME + 1); expect(title.setTitle).toHaveBeenCalledWith('a'); })); + it('with element and has children', fakeAsync(() => { + class TestDocument { + querySelector(): NzSafeAny { + return { + childNodes: [ + { + nodeType: 2, + textContent: 'b' + }, + { + nodeType: 3, + textContent: 'b' + } + ], + firstChild: { + textContent: 'a' + } + }; + } + } + genModule([{ provide: DOCUMENT, useClass: TestDocument }]); + srv.setTitle(); + tick(srv.DELAY_TIME + 1); + expect(title.setTitle).toHaveBeenCalledWith('b'); + })); it('without element', fakeAsync(() => { genModule([]); srv.setTitle();