fix undefined type#10
Merged
afc163 merged 6 commits intoreact-component:masterfrom May 14, 2024
Merged
Conversation
crazyair
commented
May 13, 2024
| const type = rule.type || ((Array.isArray(value) ? 'array' : typeof value) as RuleType); | ||
| if (!isEmptyValue(value, type)) { | ||
| rule.type = type; | ||
| if (value !== undefined && value !== null) { |
Author
There was a problem hiding this comment.
之前加 isEmptyValue 是因为如果 value 是 undefined,则 typeof value 为字符串 undefined 导致程序报错(不支持字符串 undefined)。
但是加上 isEmptyValue 后发现会将 [] 也识别为 empty,导致如果 transform 返回值是 [],rule 没有 type,最后导致校验的 message 为 v is not a string 而不是 v is required,这样就与单独写 rule=[{ required:true }] 的 message 不一致
crazyair
commented
May 13, 2024
| done(); | ||
| }); | ||
| }); | ||
| it('empty array message is "v is required"', done => { |
Author
There was a problem hiding this comment.
本测试用例用意为与没有设置 transform 的 mesasge 一致
it('empty array message is "v is required"', done => {
const value = { v: [] };
new Schema({
v: { required: true },
}).validate(value, errors => {
expect(errors).toBeTruthy();
expect(errors[0].message).toBe('v is required');
done();
});
});
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #10 +/- ##
==========================================
- Coverage 82.36% 82.33% -0.03%
==========================================
Files 25 25
Lines 652 651 -1
Branches 236 232 -4
==========================================
- Hits 537 536 -1
Misses 114 114
Partials 1 1 ☔ View full report in Codecov by Sentry. |
crazyair
commented
May 13, 2024
| if (!isEmptyValue(value, type)) { | ||
| rule.type = type; | ||
| if (value !== undefined && value !== null) { | ||
| rule.type = rule.type || ((Array.isArray(value) ? 'array' : typeof value) as RuleType); |
Author
There was a problem hiding this comment.
当 value 为 [],type 应该设置为 array,master 是没有设置
afc163
approved these changes
May 14, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.