From 5481939129bb121f947651c37829d56955d8a815 Mon Sep 17 00:00:00 2001 From: ilyamore88 Date: Wed, 5 Jan 2022 22:38:51 +0300 Subject: [PATCH 1/6] fix test of async function, fix TS type because Function is banned type --- src/components/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/utils.ts b/src/components/utils.ts index 8b402bbfe..e1e756f65 100644 --- a/src/components/utils.ts +++ b/src/components/utils.ts @@ -194,8 +194,8 @@ export function typeOf(object: any): string { * @returns {boolean} */ // eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isFunction(fn: any): fn is Function { - return typeOf(fn) === 'function'; +export function isFunction(fn: any): fn is (...args: any[]) => any { + return typeOf(fn) === 'function' || typeOf(fn) === 'asyncfunction'; } /** From 94b345cdfa33c0794b3bc17efa6742af0cae6ea7 Mon Sep 17 00:00:00 2001 From: ilyamore88 Date: Wed, 5 Jan 2022 23:05:50 +0300 Subject: [PATCH 2/6] add tests for isFunction function --- test/cypress/tests/utils.spec.ts | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/cypress/tests/utils.spec.ts diff --git a/test/cypress/tests/utils.spec.ts b/test/cypress/tests/utils.spec.ts new file mode 100644 index 000000000..89c4b2ce2 --- /dev/null +++ b/test/cypress/tests/utils.spec.ts @@ -0,0 +1,62 @@ +import { isFunction } from '../../../src/components/utils'; + +function syncFunction(): void {} + +async function asyncFunction(): Promise {} + +const syncArrowFunction = (): void => {}; + +const asyncArrowFunction = async (): Promise => {}; + +describe('isFunction function', () => { + it('should recognise sync functions', () => { + /** + * Act + */ + const commonFunctionResult = isFunction(syncFunction); + const arrowFunctionResult = isFunction(syncArrowFunction); + + /** + * Assert + */ + expect(commonFunctionResult).to.eq(true); + expect(arrowFunctionResult).to.eq(true); + }); + + it('should recognise async functions', () => { + /** + * Act + */ + const commonFunctionResult = isFunction(asyncFunction); + const arrowFunctionResult = isFunction(asyncArrowFunction); + + /** + * Assert + */ + expect(commonFunctionResult).to.eq(true); + expect(arrowFunctionResult).to.eq(true); + }); + + it('should return false if it isn\'t a function', () => { + /** + * Arrange + */ + const obj = {}; + const num = 123; + const str = '123'; + + /** + * Act + */ + const objResult = isFunction(obj); + const numResult = isFunction(num); + const strResult = isFunction(str); + + /** + * Assert + */ + expect(objResult).to.eq(false); + expect(numResult).to.eq(false); + expect(strResult).to.eq(false); + }); +}); From 8a3f55f90bc1fa07e7613825b01eb0aab410f44c Mon Sep 17 00:00:00 2001 From: ilyamore88 Date: Wed, 5 Jan 2022 23:08:24 +0300 Subject: [PATCH 3/6] fix eslint --- test/cypress/tests/utils.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cypress/tests/utils.spec.ts b/test/cypress/tests/utils.spec.ts index 89c4b2ce2..bb0cb51a6 100644 --- a/test/cypress/tests/utils.spec.ts +++ b/test/cypress/tests/utils.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ import { isFunction } from '../../../src/components/utils'; function syncFunction(): void {} From eacaf6d2accef8b1190f94a76e0d6daa48051f48 Mon Sep 17 00:00:00 2001 From: ilyamore88 Date: Thu, 13 Jan 2022 00:03:37 +0300 Subject: [PATCH 4/6] add changelog for 2.23.1 --- docs/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 52adf8fcb..a080c4b84 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 2.23.1 + +- `Fix` - Recognize async onPaste handlers in tools [#1803](https://github.com/codex-team/editor.js/issues/1803) + ### 2.23.0 - `Improvement` — *EditorConfig* — The `onChange` callback now accepts two arguments: EditorJS API and the CustomEvent with `type` and `detail` allowing to determine what happened with a Block From b7984c8fb722e335b416c7a388b4510a04f66fe2 Mon Sep 17 00:00:00 2001 From: ilyamore88 Date: Thu, 13 Jan 2022 00:12:03 +0300 Subject: [PATCH 5/6] fix changelog --- docs/CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a080c4b84..9e9b3aa3c 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,9 +1,5 @@ # Changelog -### 2.23.1 - -- `Fix` - Recognize async onPaste handlers in tools [#1803](https://github.com/codex-team/editor.js/issues/1803) - ### 2.23.0 - `Improvement` — *EditorConfig* — The `onChange` callback now accepts two arguments: EditorJS API and the CustomEvent with `type` and `detail` allowing to determine what happened with a Block @@ -24,6 +20,7 @@ - `New` — `API` — The new `UiApi` section was added. It allows accessing some editor UI nodes and methods. - `Refactoring` — Toolbox became a standalone class instead of a Module. It can be accessed only through the Toolbar module. - `Refactoring` — CI flow optimized. +- `Fix` - Recognize async onPaste handlers in tools [#1803](https://github.com/codex-team/editor.js/issues/1803) ### 2.22.3 From cb4037e99fbb65c8c58fe6cdf77449f066688e3c Mon Sep 17 00:00:00 2001 From: ilyamore88 Date: Thu, 13 Jan 2022 00:13:59 +0300 Subject: [PATCH 6/6] fix changelog --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9e9b3aa3c..e9a4f9302 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -20,7 +20,7 @@ - `New` — `API` — The new `UiApi` section was added. It allows accessing some editor UI nodes and methods. - `Refactoring` — Toolbox became a standalone class instead of a Module. It can be accessed only through the Toolbar module. - `Refactoring` — CI flow optimized. -- `Fix` - Recognize async onPaste handlers in tools [#1803](https://github.com/codex-team/editor.js/issues/1803) +- `Fix` - Recognize async `onPaste` handlers in tools [#1803](https://github.com/codex-team/editor.js/issues/1803). ### 2.22.3