Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created June 9, 2022 11:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/c3de58b0dac09d7ab97dcff49b6f15f5 to your computer and use it in GitHub Desktop.
Save NetanelBasal/c3de58b0dac09d7ab97dcff49b6f15f5 to your computer and use it in GitHub Desktop.
import { fakeAsync, tick } from '@angular/core/testing';
import { HotToastService } from '@ngneat/hot-toast';
import { createDirectiveFactory } from '@ngneat/spectator';
import { CopyDirective } from './copy.directive';
describe('CopyDirective', () => {
const createDirective = createDirectiveFactory({
directive: CopyDirective,
mocks: [HotToastService]
});
it('should copy', fakeAsync(() => {
spyOn(navigator.clipboard, 'writeText').and.callFake(() => Promise.resolve())
const text = `Clicking this button copies this text to the clipboard`;
const spectator = createDirective(`
<button copy="${text}">Copy</button>
`);
spectator.click();
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(text);
tick();
expect(spectator.inject(HotToastService).success).toHaveBeenCalled();
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment