Created
June 9, 2022 11:29
-
-
Save NetanelBasal/c3de58b0dac09d7ab97dcff49b6f15f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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