Vest ✅ Declarative validations framework
Vest 5 is mostly compatible with Vest 4, but some changes were made. In most cases, if you do not change anything, vest will keep working as it did before. However, to take advantage of the new features, you'll need to make some changes.
In previous versions of Vest, Vest continued validating fields even after one of their tests had failed. V5 changes that to improve the runtime performance, and instead, Vest will halt further validations of a given field if it failed. This was an opt-in feature, and it can now be removed.
- import {create, test, eager} from 'vest';
+ import {create, test} from 'vest';
const suite = create(() => {
- eager();
test(/*...*/);
});
To bring back the previous behavior, use the mode
function that alters the execution mode:
- import {create, test} from 'vest';
+ import {create, test, mode, Modes} from 'vest';
const suite = create(() => {
+ eager(Modes.ALL);
test(/*...*/);
});
This also means that if you've used skipWhen
to avoid running of failing fields, you can now remove it:
- import {create, test, skipWhen} from 'vest';
+ import {create, test} from 'vest';
const suite = create(() => {
- skipWhen(res => res.hasErrors('username'), () => {
test('username', 'username already taken', () => {
// ...
});
- });
});
In previous versions, you had to call suite.get()
to access the different methods, such as getErrors
and isValid
. In V5, these methods are available directly on the suite object.
- suite.get().getErrors('username');
+ suite.getErrors('username')
- suite.get().isValid();
+ suite.isValid()
hasError
and hasWarning
methodsThe result object has two new methods: hasError and hasWarning. They return a boolean value indicating whether a given field has an error or a warning. With these new methods, you can display the first error of a field.
- res.getErrors('username')[0]
+ res.hasError('username')
Vest 5 removes the dedicated group interface for skip and only, and instead allows you to call skip and only directly within the groups.
const suite = create(() => {
- skip.group('group1', 'username');
group('group1', () => {
+ skip('username');
test('username', 'message', () => {
// ...
});
});
});
const suite = create(() => {
- skip.group('group1');
group('group1', () => {
+ skip(true);
test('field1', 'message', () => {
// ...
});
});
});
In previous versions, optional fields only took into consideration whether the tests ran or not. In V5 optional fields also search the data object passed to the suite. If it has an object with the optional field in it, and the optional field is blank - the test will be considered valid even if it is not passing.
In previous versions, as a user of Vest you had to set up your own state-reset mechanism. Vest now has a staticSuite
export that does that for you.
- import {create} from 'vest';
+ import {staticSuite} from 'vest';
- const suite = create(() => {/*...*/});
+ const suite = staticSuite(() => /*...*/});
- function ServerValidation() {
- suite.reset();
- suite();
- }
All of Vest's methods are now typed and make use of generics to enforce correct usage throughout your suite.
Vest 5 uses Javascript Proxies, which were introduced in ES2015. Therefore, Vest 5 no longer supports pre-ES2015 versions of Javascript. If you need to support older browsers, you can still use Vest 4.
https://github.com/ealush/vest/commit/7a17ef067457c8ce2f2204ab1e63a250b18f66ae patch(context): simplify context by removing the ancestry registration (ealush)
https://github.com/ealush/vest/commit/d7d0893fd460baac286c5e409eaed6afdcb96d2b feat(vest): Add boolean control for optional fields (https://github.com/ealush/vest/pull/910) (Evyatar) https://github.com/ealush/vest/commit/8284ce29c8c67c56e89e61b8be0b0650f423005d patch(vest): use string module from vest-utils (ealush)
9b46fb6 types(vest): add suiteName type to SuiteResult (ealush) b94b568 patch(vest): use suiteSelectors from vest top level api in parser module (ealush) 24e4cea added(vest): expose suiteSelectors as a top level API (ealush) 1812e68 patch(vest): remove unneeded base object in context assignment (ealush) 590ad76 patch(vest): Remove suiteSummary from context (ealush) e8dbbc9 patch(vest): move suite selectors out into their own module for easier consumption by external sources (#906) (Evyatar) 8597af2 patch(vest): Call done callback immediately when field does not exist (ealush) 17c39f6 types(vest): improve getFailures overload (ealush) d4d4cb1 patch(vest): Remove unneeded empty check in hasRemainigTests (ealush)
b062abb types(vest): Add a dedicated VestTests plural type (ealush) f28a1a6 tests(vest): Completely remove itWithContext (ealush)
555bf85 patch(n4s): replace array with counter in oneOf (ealush) a6a86a7 patch(n4s): Simplify rule result (ealush) 44721e6 types(n4s): add isUndefined type guard (ealush)
b11c779 patch(context): use internally(ealush)
https://github.com/ealush/vest/commit/a5db77c78d8afd159ddef9104a29f436948dd76a tests(vest): Add sanity tests for group validity (ealush) https://github.com/ealush/vest/commit/49096b1959d54dacbea9baf6528c0132bc0b307a patch(vest): replace Cursor with IsolateCursor (https://github.com/ealush/vest/pull/869) (Evyatar) https://github.com/ealush/vest/commit/4dbb9c0d02d46e1a360e2a115acc827d71b89be6 minor(vest): isValidByGroup (https://github.com/ealush/vest/pull/856) (Evyatar) https://github.com/ealush/vest/commit/6a67315f0da0e5cd7a2915aff4ab6520ca841759 tests(vest): make test.memo test more resilient (ealush)
https://github.com/ealush/vest/commit/870a2ed92a07797b16b3c04ac26fca0d0ea2896b tests(vest): Remove most itWithContext instances from tests (ealush) https://github.com/ealush/vest/commit/1944122b165fd4c69c7ecb0ce3cf846981948d30 patch(vest): use isolate hook directly (ealush) https://github.com/ealush/vest/commit/33cd6d9bf5cab47250202c4240e93d009bf42888 patch(vest): Use the same test mutation function everywhere (ealush)