From 93405d54d8a496c00fd8e6f63578eb9f7c1a0d30 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sun, 8 Aug 2021 14:30:12 +0300 Subject: [PATCH] #49 : Add unit tests --- src/utils/event.js | 3 +-- src/utils/math.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/utils/math.test.js diff --git a/src/utils/event.js b/src/utils/event.js index 354aeea..ac9119d 100644 --- a/src/utils/event.js +++ b/src/utils/event.js @@ -7,14 +7,13 @@ export function removeResizeEventListener(cb) { } export function createDispatcher(source) { - function dispatch(event, data) { + return function (event, data) { source.dispatchEvent( new CustomEvent(event, { detail: data, }) ) } - return dispatch } export function getIsTouchable() { diff --git a/src/utils/math.test.js b/src/utils/math.test.js new file mode 100644 index 0000000..1307b7c --- /dev/null +++ b/src/utils/math.test.js @@ -0,0 +1,19 @@ +import { + getDistance, +} from './math.js' + +describe('getDistance', () => { + it('returns correct distance between 2 points laying in one horizontal line', () => { + const p1 = { x: 0, y: 0 } + const p2 = { x: 5, y: 0 } + + expect(getDistance(p1, p2)).toBe(5) + }) + + it('returns correct distance between 2 points', () => { + const p1 = { x: 1, y: 1 } + const p2 = { x: 5, y: 4 } + + expect(getDistance(p1, p2)).toBe(5) + }) +})