-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Improve code and simplify logic #2651
Conversation
} | ||
|
||
return [children]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
children 为 undefined 的情况和原来输出是否一样。重构建议先补充相关的单元测试用例。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想问一下补充相关的单元测试用例,可以在node.test.ts文件中添加测试用例,来测试函数在重构前后输出结果是否一样吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以的。
@@ -53,8 +54,63 @@ describe('Node 方法测试', () => { | |||
designer = null; | |||
project = null; | |||
}); | |||
//测试 children 为 undefined 时重构前后输出结果 | |||
it('initialChildren and initialChildren2 should return the same result when children is undefined', () => { | |||
//重构前的 Node 的 initialChildren 方法 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你的测试不应该自己模拟函数,应该用类似于下面的方式写。
// 导入Node类
const { Node } = require('./Node'); // 假设Node类位于Node.js文件中
// 创建一个测试套件
describe('Node Class', () => {
// 创建一个测试用例
it('should initialize children array with empty array when children is null', () => {
// 创建一个Node实例
const node = new Node();
// 调用initialChildren方法并传入null作为参数
const result = node.initialChildren(null);
// 预期结果是一个空数组
expect(result).to.deep.equal([]);
});
// 创建更多的测试用例来测试其他情况...
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK 问一下怎么比较改进前的方法🤔️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要比较改进前的方法,主要看改进后的输入输出。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1葫画瓢 这样画的可以嘛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以的,可以再加一下 0 和 false 的测试用例。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
}); | ||
|
||
// Case 5: When children is 0 | ||
test('initialChildren returns result of initialChildren function when children is null ', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Case 5: When children is 0,
这里和 Case 4 是一样的。Case 6 也是
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case 4、Case 5、 Case 6 不应该是一样的代码。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK了
* fix: Improve code and simplify logic
改进代码逻辑