Skip to content

Commit 37f35ce

Browse files
wilsonjack163126@sina.com
authored andcommitted
fix(async-map): judge whether objArr is empty to resolve or callback, it fixs no response issure when there is no rules for inputs.
1 parent 908957d commit 37f35ce

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

__tests__/validator.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,21 @@ describe('validator', () => {
416416
done();
417417
});
418418
});
419+
420+
it('works for no rules fields', done => {
421+
new Schema({
422+
v: [],
423+
v2: [],
424+
})
425+
.validate({
426+
v: 2,
427+
v2: 1,
428+
})
429+
.then(e => {
430+
expect(e).toBeUndefined();
431+
done();
432+
});
433+
});
419434
});
420435
});
421436
});

src/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ export function asyncMap(objArr, option, func, callback) {
180180
: resolve();
181181
}
182182
};
183+
if (!objArrKeys.length) {
184+
callback(results)
185+
resolve()
186+
}
183187
objArrKeys.forEach(key => {
184188
const arr = objArr[key];
185189
if (firstFields.indexOf(key) !== -1) {

0 commit comments

Comments
 (0)