license import { createDirectiveFactory , SpectatorDirective , } from '@ngneat/spectator/jest' ; import { ClickOutsideDirective } from './click-outside.directive' ; describe ( 'ClickOutsideDirective ' , ( ) => { let spectator ; const createDirective = createDirectiveFactory ( ClickOutsideDirective ) ; it ( 'should get the instance' , ( ) => { spectator = createDirective ( `<div appClickOutside>Testing ClickOutsideDirective</div>` ) ; const instance = spectator . directive ; expect ( instance ) . toBeDefined ( ) ; } ) ; it ( 'emits on click outside' , ( ) => { spectator = createDirective ( `<div appClickOutside>Testing ClickOutsideDirective</div><div data-random-loc><div>` ) ; const outsideEl = spectator . query ( '[data-random-loc]' ) ! ; let output ; spectator . output ( 'clickOutside' ) . subscribe ( ( result ) => { output = result ; } ) ; expect ( output ) . toBeFalsy ( ) ; spectator . dispatchMouseEvent ( spectator . element , 'click' ) ; expect ( output ) . toBeFalsy ( ) ; spectator . dispatchMouseEvent ( outsideEl , 'click' ) ; expect ( output ) . toBeTruthy ( ) ; } ) ; } ) ;