From f4cfd8f7eca1578b7ca9ab8148ce7d6e75306d68 Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Wed, 19 Jun 2019 17:01:08 +0800 Subject: [PATCH] test(module:typography): fix test --- .../services/nz-copy-to-clipboard.service.ts | 66 +++++++++++-------- components/core/services/public-api.ts | 1 - components/typography/nz-typography.spec.ts | 2 +- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/components/core/services/nz-copy-to-clipboard.service.ts b/components/core/services/nz-copy-to-clipboard.service.ts index 37e9eaf5774..51133745c4c 100644 --- a/components/core/services/nz-copy-to-clipboard.service.ts +++ b/components/core/services/nz-copy-to-clipboard.service.ts @@ -1,3 +1,11 @@ +/** + * @license + * Copyright Alibaba.com 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://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE + */ + import { DOCUMENT } from '@angular/common'; import { Inject, Injectable } from '@angular/core'; @@ -5,38 +13,40 @@ import { Inject, Injectable } from '@angular/core'; providedIn: 'root' }) export class NzCopyToClipboardService { - - constructor(@Inject(DOCUMENT) private document: Document) { } + // tslint:disable-next-line:no-any + constructor(@Inject(DOCUMENT) private document: any) {} copy(text: string): Promise { - return new Promise((resolve, reject): void => { - let copyTextArea = null; - try { - // tslint:disable-next-line no-any - copyTextArea = this.document.createElement('textarea') as any; - copyTextArea.style!.all = 'unset'; - copyTextArea.style.position = 'fixed'; - copyTextArea.style.top = '0'; - copyTextArea.style.clip = 'rect(0, 0, 0, 0)'; - copyTextArea.style.whiteSpace = 'pre'; - copyTextArea.style.webkitUserSelect = 'text'; - copyTextArea.style!.MozUserSelect = 'text'; - copyTextArea.style.msUserSelect = 'text'; - copyTextArea.style.userSelect = 'text'; - this.document.body.appendChild(copyTextArea); - copyTextArea.value = text; - copyTextArea.select(); + return new Promise( + (resolve, reject): void => { + let copyTextArea = null; + try { + // tslint:disable-next-line no-any + copyTextArea = this.document.createElement('textarea') as any; + copyTextArea.style!.all = 'unset'; + copyTextArea.style.position = 'fixed'; + copyTextArea.style.top = '0'; + copyTextArea.style.clip = 'rect(0, 0, 0, 0)'; + copyTextArea.style.whiteSpace = 'pre'; + copyTextArea.style.webkitUserSelect = 'text'; + copyTextArea.style!.MozUserSelect = 'text'; + copyTextArea.style.msUserSelect = 'text'; + copyTextArea.style.userSelect = 'text'; + this.document.body.appendChild(copyTextArea); + copyTextArea.value = text; + copyTextArea.select(); - const successful = this.document.execCommand('copy'); - if (!successful) { - reject(text); - } - resolve(text); - } finally { - if (copyTextArea) { - this.document.body.removeChild(copyTextArea); + const successful = this.document.execCommand('copy'); + if (!successful) { + reject(text); + } + resolve(text); + } finally { + if (copyTextArea) { + this.document.body.removeChild(copyTextArea); + } } } - }); + ); } } diff --git a/components/core/services/public-api.ts b/components/core/services/public-api.ts index c171a442eb8..b7976ddc771 100644 --- a/components/core/services/public-api.ts +++ b/components/core/services/public-api.ts @@ -9,4 +9,3 @@ export * from './nz-measure-scrollbar.service'; export * from './update-host-class.service'; export * from './nz-copy-to-clipboard.service'; - diff --git a/components/typography/nz-typography.spec.ts b/components/typography/nz-typography.spec.ts index 81a4bcbaa9a..a95bbbfce91 100644 --- a/components/typography/nz-typography.spec.ts +++ b/components/typography/nz-typography.spec.ts @@ -196,7 +196,7 @@ export class NzTestTypographyCopyComponent { ` }) export class NzTestTypographyEditComponent { - @ViewChild(NzTypographyComponent) nzTypographyComponent: NzTypographyComponent; + @ViewChild(NzTypographyComponent, { static: true }) nzTypographyComponent: NzTypographyComponent; str = 'This is an editable text.'; onChange = (text: string): void => { this.str = text;