[ci:force] Fix failing copy to clipboard test (#7631)

This commit is contained in:
Pablo Martinez Garcia 2022-05-12 13:06:10 +02:00 committed by GitHub
parent 24e5893a56
commit fa82d3216f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,20 +121,20 @@ describe('CopyClipboardDirective', () => {
it('should copy the content of element when click it', fakeAsync(() => { it('should copy the content of element when click it', fakeAsync(() => {
const spanHTMLElement = element.querySelector<HTMLInputElement>('span'); const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
fixture.detectChanges(); fixture.detectChanges();
spyOn(document, 'execCommand'); spyOn(navigator.clipboard, 'writeText');
spanHTMLElement.dispatchEvent(new Event('click')); spanHTMLElement.dispatchEvent(new Event('click'));
tick(); tick();
fixture.detectChanges(); fixture.detectChanges();
expect(document.execCommand).toHaveBeenCalledWith('copy'); expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy');
})); }));
it('should not copy the content of element when click it', fakeAsync(() => { it('should not copy the content of element when click it', fakeAsync(() => {
const spanHTMLElement = element.querySelector<HTMLInputElement>('span'); const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
fixture.detectChanges(); fixture.detectChanges();
spyOn(document, 'execCommand'); spyOn(navigator.clipboard, 'writeText');
spanHTMLElement.dispatchEvent(new Event('mouseleave')); spanHTMLElement.dispatchEvent(new Event('mouseleave'));
tick(); tick();
fixture.detectChanges(); fixture.detectChanges();
expect(document.execCommand).not.toHaveBeenCalled(); expect(navigator.clipboard.writeText).not.toHaveBeenCalled();
})); }));
}); });