Skip to content

Commit

Permalink
tests: oneOf
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Mar 31, 2022
1 parent 1c13dc0 commit 2fcf0c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
8 changes: 1 addition & 7 deletions packages/n4s/src/plugins/compounds/__tests__/oneOf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ import 'compounds';
describe('enforce.oneOf', () => {
it('Should fail when multiple enforcements are met', () => {
expect(
User.run({
id: 11,
name: {
first: 'John',
last: 'Doe',
},
})
enforce.oneOf(enforce.isNumber(), enforce.greaterThan(2)).run(3)
).toEqual(ruleReturn.failing());
});

Expand Down
8 changes: 4 additions & 4 deletions packages/n4s/src/plugins/compounds/oneOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const REQUIRED_COUNT = 1;
export function oneOf(value: unknown, ...rules: Lazy[]): RuleDetailedResult {
const passing: RuleDetailedResult[] = [];
rules.some(rule => {
if (longerThan(passing, REQUIRED_COUNT)) {
return false;
}

const res = runLazyRule(rule, value);

if (res.pass) {
passing.push(res);
}

if (longerThan(passing, REQUIRED_COUNT)) {
return false;
}
});

return ruleReturn(lengthEquals(passing, REQUIRED_COUNT));
Expand Down

0 comments on commit 2fcf0c9

Please sign in to comment.