Skip to content

Commit 8a20841

Browse files
committed
patch(vest): disallow bad include input
1 parent 584be8a commit 8a20841

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/vest/src/hooks/__tests__/include.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ describe('include', () => {
88
cb2 = jest.fn(() => false);
99
});
1010

11+
describe('When not passing a string fieldName', () => {
12+
it('Should throw an error', () => {
13+
// @ts-ignore
14+
expect(() => vest.include({})).toThrow();
15+
// @ts-ignore
16+
expect(() => vest.include(undefined)).toThrow();
17+
});
18+
});
19+
1120
describe('There is an `onlyd` field', () => {
1221
describe('`include` is run as-is without modifiers', () => {
1322
it('Should run the included test along with the onlyd test', () => {

packages/vest/src/hooks/include.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import defaultTo from 'defaultTo';
22
import hasOwnProperty from 'hasOwnProperty';
3+
import invariant from 'invariant';
34
import { isStringValue } from 'isStringValue';
45
import optionalFunctionValue from 'optionalFunctionValue';
56

@@ -14,9 +15,7 @@ export default function include(fieldName: string): {
1415
const context = ctx.useX();
1516
const { inclusion, exclusion } = context;
1617

17-
if (!fieldName) {
18-
return { when };
19-
}
18+
invariant(isStringValue(fieldName));
2019

2120
inclusion[fieldName] = defaultTo(exclusion.tests[fieldName], true);
2221

0 commit comments

Comments
 (0)