Skip to content

Commit 6212453

Browse files
liujupingJackLian
authored andcommitted
test(utils): add ut to package/utils
1 parent 938c71f commit 6212453

74 files changed

Lines changed: 2621 additions & 439 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/utils/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const jestConfig = {
1111
'!**/node_modules/**',
1212
'!**/vendor/**',
1313
],
14+
setupFilesAfterEnv: ['./jest.setup.js'],
1415
};
1516

1617
// 只对本仓库内的 pkg 做 mapping

packages/utils/jest.setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

packages/utils/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"main": "lib/index.js",
1010
"module": "es/index.js",
1111
"scripts": {
12-
"test": "build-scripts test --config build.test.json",
12+
"test": "build-scripts test --config build.test.json --jest-coverage",
1313
"build": "build-scripts build"
1414
},
1515
"dependencies": {
@@ -21,8 +21,11 @@
2121
},
2222
"devDependencies": {
2323
"@alib/build-scripts": "^0.1.18",
24+
"@testing-library/jest-dom": "^6.1.4",
25+
"@testing-library/react": "^11.2.7",
2426
"@types/node": "^13.7.1",
25-
"@types/react": "^16"
27+
"@types/react": "^16",
28+
"react-dom": "^16.14.0"
2629
},
2730
"publishConfig": {
2831
"access": "public",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { IPublicTypeActionContentObject } from '@alilc/lowcode-types';
2+
import { isObject } from '../is-object';
23

34
export function isActionContentObject(obj: any): obj is IPublicTypeActionContentObject {
4-
return obj && typeof obj === 'object';
5+
return isObject(obj);
56
}

packages/utils/src/check-types/is-custom-view.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { isValidElement } from 'react';
22
import { isReactComponent } from '../is-react';
33
import { IPublicTypeCustomView } from '@alilc/lowcode-types';
44

5-
65
export function isCustomView(obj: any): obj is IPublicTypeCustomView {
7-
return obj && (isValidElement(obj) || isReactComponent(obj));
6+
if (!obj) {
7+
return false;
8+
}
9+
return isValidElement(obj) || isReactComponent(obj);
810
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { IPublicEnumDragObjectType } from '@alilc/lowcode-types';
2+
import { isObject } from '../is-object';
23

34
export function isDragAnyObject(obj: any): boolean {
4-
return obj && obj.type !== IPublicEnumDragObjectType.NodeData && obj.type !== IPublicEnumDragObjectType.Node;
5+
if (!isObject(obj)) {
6+
return false;
7+
}
8+
return obj.type !== IPublicEnumDragObjectType.NodeData && obj.type !== IPublicEnumDragObjectType.Node;
59
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { IPublicEnumDragObjectType, IPublicTypeDragNodeDataObject } from '@alilc/lowcode-types';
2+
import { isObject } from '../is-object';
23

34
export function isDragNodeDataObject(obj: any): obj is IPublicTypeDragNodeDataObject {
4-
return obj && obj.type === IPublicEnumDragObjectType.NodeData;
5+
if (!isObject(obj)) {
6+
return false;
7+
}
8+
return obj.type === IPublicEnumDragObjectType.NodeData;
59
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { IPublicEnumDragObjectType, IPublicModelNode, IPublicTypeDragNodeObject } from '@alilc/lowcode-types';
2+
import { isObject } from '../is-object';
23

34
export function isDragNodeObject<Node = IPublicModelNode>(obj: any): obj is IPublicTypeDragNodeObject<Node> {
4-
return obj && obj.type === IPublicEnumDragObjectType.Node;
5+
if (!isObject(obj)) {
6+
return false;
7+
}
8+
return obj.type === IPublicEnumDragObjectType.Node;
59
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import { isFunction } from '../is-function';
12
import { isReactClass } from '../is-react';
23
import { IPublicTypeDynamicSetter } from '@alilc/lowcode-types';
34

4-
55
export function isDynamicSetter(obj: any): obj is IPublicTypeDynamicSetter {
6-
return obj && typeof obj === 'function' && !isReactClass(obj);
6+
if (!isFunction(obj)) {
7+
return false;
8+
}
9+
return !isReactClass(obj);
710
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function isFunction(obj: any): obj is Function {
2+
return obj && typeof obj === 'function';
3+
}

0 commit comments

Comments
 (0)