Skip to content

Commit bdefbd2

Browse files
committed
chore: add some falsy tests
1 parent 6879832 commit bdefbd2

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/base.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,15 @@ internals.Base = class {
484484
return true;
485485
}
486486

487-
for (const item of when.switch) {
488-
if (item.then?.isAsync()) {
489-
return true;
490-
}
487+
if (when.switch) {
488+
for (const item of when.switch) {
489+
if (item.then?.isAsync()) {
490+
return true;
491+
}
491492

492-
if (item.otherwise?.isAsync()) {
493-
return true;
493+
if (item.otherwise?.isAsync()) {
494+
return true;
495+
}
494496
}
495497
}
496498
}

test/isAsync.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,33 @@ describe('isAsync()', () => {
7171
is: 'b',
7272
otherwise: Joi.string().external(() => {})
7373
}).isAsync()).to.be.true();
74+
expect(Joi.any().when('a', {
75+
is: 'b',
76+
otherwise: Joi.string()
77+
}).isAsync()).to.be.false();
7478
expect(Joi.any().when('a', {
7579
switch: [
7680
{ is: 'b', then: Joi.string() },
7781
{ is: 'c', then: Joi.number().external(() => {}), otherwise: Joi.string() }
7882
]
7983
}).isAsync()).to.be.true();
84+
expect(Joi.any().when('a', {
85+
switch: [
86+
{ is: 'b', then: Joi.string() },
87+
{ is: 'c', then: Joi.number(), otherwise: Joi.string() }
88+
]
89+
}).isAsync()).to.be.false();
8090
expect(Joi.any().when('a', {
8191
switch: [
8292
{ is: 'b', then: Joi.string() },
8393
{ is: 'c', then: Joi.string(), otherwise: Joi.number().external(() => {}) }
8494
]
8595
}).isAsync()).to.be.true();
96+
expect(Joi.any().when('a', {
97+
switch: [
98+
{ is: 'b', then: Joi.string() },
99+
{ is: 'c', then: Joi.string(), otherwise: Joi.number() }
100+
]
101+
}).isAsync()).to.be.false();
86102
});
87103
});

0 commit comments

Comments
 (0)