mirror of
https://github.com/codex-team/editor.js
synced 2024-06-07 16:32:22 +02:00
[Fix] isFunction function for async functions (#1857)
* fix test of async function, fix TS type because Function is banned type * add tests for isFunction function * fix eslint * add changelog for 2.23.1 * fix changelog * fix changelog
This commit is contained in:
parent
ff91466b14
commit
40c05173a9
|
@ -20,6 +20,7 @@
|
||||||
- `New` — `API` — The new `UiApi` section was added. It allows accessing some editor UI nodes and methods.
|
- `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` — Toolbox became a standalone class instead of a Module. It can be accessed only through the Toolbar module.
|
||||||
- `Refactoring` — CI flow optimized.
|
- `Refactoring` — CI flow optimized.
|
||||||
|
- `Fix` - Recognize async `onPaste` handlers in tools [#1803](https://github.com/codex-team/editor.js/issues/1803).
|
||||||
|
|
||||||
### 2.22.3
|
### 2.22.3
|
||||||
|
|
||||||
|
|
|
@ -194,8 +194,8 @@ export function typeOf(object: any): string {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export function isFunction(fn: any): fn is Function {
|
export function isFunction(fn: any): fn is (...args: any[]) => any {
|
||||||
return typeOf(fn) === 'function';
|
return typeOf(fn) === 'function' || typeOf(fn) === 'asyncfunction';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
63
test/cypress/tests/utils.spec.ts
Normal file
63
test/cypress/tests/utils.spec.ts
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||||
|
import { isFunction } from '../../../src/components/utils';
|
||||||
|
|
||||||
|
function syncFunction(): void {}
|
||||||
|
|
||||||
|
async function asyncFunction(): Promise<void> {}
|
||||||
|
|
||||||
|
const syncArrowFunction = (): void => {};
|
||||||
|
|
||||||
|
const asyncArrowFunction = async (): Promise<void> => {};
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue