Skip to content

Commit

Permalink
test(Utilities): test isMouseEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincharity committed Jul 29, 2019
1 parent e6d1826 commit 7c0432c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions terminus-ui/utilities/src/type-coercion/is-mouse-event.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createMouseEvent } from '@terminus/ngx-tools/testing';

import { isMouseEvent } from './is-mouse-event';


describe(`isMouseEvent`, function() {

test(`should return true for mouse events`, function() {
const fakeMouseEvent = createMouseEvent('click');
expect(isMouseEvent(fakeMouseEvent)).toEqual(true);
});


test(`should return false for anything that is not a mouse event`, function() {
const badValues = [
null,
void 0,
1,
0,
'foo',
{},
'',
];

for (const value of badValues) {
expect(isMouseEvent(value as any)).toEqual(false);
}
});

});
2 changes: 1 addition & 1 deletion terminus-ui/utilities/src/type-coercion/is-mouse-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import { isSet } from '@terminus/ngx-tools';
*/
// tslint:disable-next-line no-any
export function isMouseEvent(x: any): x is MouseEvent {
return isSet(x.relatedTarget);
return !!x && isSet(x.relatedTarget);
}

0 comments on commit 7c0432c

Please sign in to comment.