Skip to content

Commit 2fcf0c9

Browse files
committed
tests: oneOf
1 parent 1c13dc0 commit 2fcf0c9

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

packages/n4s/src/plugins/compounds/__tests__/oneOf.test.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import 'compounds';
77
describe('enforce.oneOf', () => {
88
it('Should fail when multiple enforcements are met', () => {
99
expect(
10-
User.run({
11-
id: 11,
12-
name: {
13-
first: 'John',
14-
last: 'Doe',
15-
},
16-
})
10+
enforce.oneOf(enforce.isNumber(), enforce.greaterThan(2)).run(3)
1711
).toEqual(ruleReturn.failing());
1812
});
1913

packages/n4s/src/plugins/compounds/oneOf.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const REQUIRED_COUNT = 1;
99
export function oneOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult {
1010
const passing: RuleDetailedResult[] = [];
1111
rules.some(rule => {
12-
if (longerThan(passing, REQUIRED_COUNT)) {
13-
return false;
14-
}
15-
1612
const res = runLazyRule(rule, value);
1713

1814
if (res.pass) {
1915
passing.push(res);
2016
}
17+
18+
if (longerThan(passing, REQUIRED_COUNT)) {
19+
return false;
20+
}
2121
});
2222

2323
return ruleReturn(lengthEquals(passing, REQUIRED_COUNT));

0 commit comments

Comments
 (0)