vest 4.0.0-dev-cc5cf5 → 4.0.0-dev-31f012

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +52 -44
  2. package/README.md +7 -1
  3. package/dist/cjs/classnames.development.js +3 -3
  4. package/dist/cjs/classnames.production.js +1 -1
  5. package/dist/cjs/promisify.development.js +1 -1
  6. package/dist/cjs/promisify.production.js +1 -1
  7. package/dist/cjs/vest.development.js +394 -180
  8. package/dist/cjs/vest.production.js +1 -1
  9. package/dist/es/classnames.development.js +3 -3
  10. package/dist/es/classnames.production.js +1 -1
  11. package/dist/es/promisify.development.js +1 -1
  12. package/dist/es/promisify.production.js +1 -1
  13. package/dist/es/vest.development.js +394 -180
  14. package/dist/es/vest.production.js +1 -1
  15. package/dist/umd/classnames.development.js +3 -3
  16. package/dist/umd/classnames.production.js +1 -1
  17. package/dist/umd/promisify.development.js +1 -1
  18. package/dist/umd/promisify.production.js +1 -1
  19. package/dist/umd/vest.development.js +394 -180
  20. package/dist/umd/vest.production.js +1 -1
  21. package/package.json +1 -1
  22. package/testUtils/testObjects.ts +11 -2
  23. package/types/classnames.d.ts +2 -2
  24. package/types/vest.d.ts +10 -3
  25. package/docs/.nojekyll +0 -0
  26. package/docs/README.md +0 -107
  27. package/docs/_assets/favicon.ico +0 -0
  28. package/docs/_assets/vest-logo.png +0 -0
  29. package/docs/_sidebar.md +0 -14
  30. package/docs/cross_field_validations.md +0 -34
  31. package/docs/enforce.md +0 -11
  32. package/docs/exclusion.md +0 -129
  33. package/docs/getting_started.md +0 -72
  34. package/docs/group.md +0 -142
  35. package/docs/index.html +0 -41
  36. package/docs/migration.md +0 -202
  37. package/docs/n4s/rules.md +0 -1282
  38. package/docs/node.md +0 -36
  39. package/docs/optional.md +0 -103
  40. package/docs/result.md +0 -249
  41. package/docs/state.md +0 -102
  42. package/docs/test.md +0 -172
  43. package/docs/utilities.md +0 -109
  44. package/docs/warn.md +0 -82
package/docs/group.md DELETED
@@ -1,142 +0,0 @@
1
- # Grouping tests
2
-
3
- In many cases it can be helpful to group tests together so you can include or exclude a portion of the suite with a single condition.
4
- Similar to the `describe` and `context` features provided by unit testing frameworks, Vest provides `group`.
5
-
6
- [Try on CodeSandbox (React)](https://codesandbox.io/s/vest-group-example-react-4i2ne)
7
-
8
- ```js
9
- import { create, test, group, enforce, skip } from 'vest';
10
-
11
- create(data => {
12
- skip.group(data.userExists ? 'signUp' : 'signIn');
13
-
14
- test('userName', "Can't be empty", () => {
15
- enforce(data.username).isNotEmpty();
16
- });
17
- test('password', "Can't be empty", () => {
18
- enforce(data.password).isNotEmpty();
19
- });
20
-
21
- group('signIn', () => {
22
- test(
23
- 'userName',
24
- 'User not found. Please check if you typed it correctly.',
25
- findUserName(data.username)
26
- );
27
- });
28
-
29
- group('signUp', () => {
30
- test('email', 'Email already registered', isEmailRegistered(data.email));
31
-
32
- test('age', 'You must be at least 18 years old to join', () => {
33
- enforce(data.age).largerThanOrEquals(18);
34
- });
35
- });
36
- });
37
- ```
38
-
39
- ## Why use `group` and not just wrap the tests with an `if` statement?
40
-
41
- In many cases it is sufficient to just use an `if` statement. The benefit of using `group` is that when skipping (either using [skip or only](./exclusion)), Vest will merge the previous group result with the current suite. This is mostly suitable for cases like demonstrated in the first example of the multi stage form.
42
-
43
- ## Use cases
44
-
45
- ### 1. Multi stage form
46
-
47
- You may have in your application a multi-screen form, in which you want to validate each screen individually, but submit it all at once.
48
-
49
- ```js
50
- // suite.js
51
- import { create, test, group, enforce, only } from 'vest';
52
-
53
- const suite = create((data, currentTab) => {
54
- only.group(currentScreen);
55
-
56
- group('overview_tab', () => {
57
- test('productTitle', 'Must be at least 5 chars.', () => {
58
- enforce(data.productTitle).longerThanOrEquals(5);
59
- });
60
-
61
- test('productDescription', "Can't be longer than 2500 chars.", () => {
62
- enforce(data.productDescription).shorterThanOrEquals(2500);
63
- });
64
-
65
- test('productTags', 'Please provide up to 5 tags', () => {
66
- enforce(data.tags).lengthEquals(5);
67
- });
68
- });
69
-
70
- group('pricing_tab', () => {
71
- test('price', '5$ or more.', () => {
72
- enforce(data.price).lte(5);
73
- });
74
-
75
- test('productExtras', "Can't be empty.", () => {
76
- enforce(data.extras).isNotEmpty();
77
- });
78
- });
79
- });
80
-
81
- export default suite;
82
- ```
83
-
84
- ```js
85
- // myFeature.js
86
-
87
- suite(data, 'overview_tab'); // will only validate 'overview_tab' group
88
- suite(data, 'pricing_tab'); // will only validate 'pricing_tab' group
89
- ```
90
-
91
- ### 2. Skipping tests with shared fields
92
-
93
- You sometimes want to skip some tests on a certain condition, but still run other tests with the same field-name.
94
-
95
- In the example below, we don't mind skipping the `balance` field directly, but if we skip the `quantity` field directly, it won't be tested at all - even though it has one test outside of the group. That's why we skip the `used_promo`.
96
-
97
- ```js
98
- import { create, test, group, enforce, skip } from 'vest';
99
-
100
- const suite = create(data => {
101
- if (!data.usedPromo) skip.group('used_promo');
102
- if (!data.paysWithBalance) skip.group('balance');
103
-
104
- test(
105
- 'balance',
106
- 'Balance is lower than product price',
107
- hasSufficientFunds(data.productId)
108
- );
109
-
110
- test('quantity', `Quantity on this item is limited to ${data.limit}`, () => {
111
- enforce(data.quantity).lessThanOrEquals(data.limit);
112
- });
113
-
114
- group('used_promo', () => {
115
- test(
116
- 'quantity',
117
- 'promo code purchases are limited to one item only',
118
- () => {
119
- enforce(data.quantity).equals(1);
120
- }
121
- );
122
-
123
- test(
124
- 'promoCode',
125
- 'Promo code can only be used once',
126
- isPromoCodeUsed(data.usedPromo)
127
- );
128
- });
129
- });
130
- ```
131
-
132
- ## Querying the result object for groups
133
-
134
- Groups represent a portion of your validation suite, so when using `group`, you are likely to need to get the group-specific validation results.
135
- Your result object exposes the following methods:
136
-
137
- - [_hasErrorsByGroup_](./result#haserrorsbygroup-and-haswarningsbygroup-functions)
138
- - [_hasWarningsByGroup_](./result#haserrorsbygroup-and-haswarningsbygroup-functions)
139
- - [_hasErrorsByGroup_](./result#geterrorsbygroup-and-getwarningsbygroup-functions)
140
- - [_hasWarningsByGroup_](./result#geterrorsbygroup-and-getwarningsbygroup-functions)
141
-
142
- Read more about these methods in [the result object](./result).
package/docs/index.html DELETED
@@ -1,41 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <title>Vest - Declarative Validations</title>
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7
- <meta name="description" content="Validation Test" />
8
- <meta
9
- name="viewport"
10
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
11
- />
12
- <link rel="icon" href="./_assets/favicon.ico" />
13
- <link
14
- rel="stylesheet"
15
- href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css"
16
- />
17
- <link
18
- rel="stylesheet"
19
- href="https://cdn.jsdelivr.net/npm/prismjs@1.22.0/themes/prism-tomorrow.css"
20
- />
21
- </head>
22
- <body>
23
- <div id="app"></div>
24
- <script>
25
- window.$docsify = {
26
- name: 'vest',
27
- logo: '/_assets/vest-logo.png',
28
- repo: 'https://github.com/ealush/vest',
29
- search: 'auto',
30
- loadSidebar: true,
31
- subMaxLevel: 2,
32
- themeColor: '#5BA9D8',
33
- };
34
- </script>
35
- <script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
36
- <script src="https://cdn.jsdelivr.net/npm/docsify-themeable@0"></script>
37
- <script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
38
- <script src="//unpkg.com/vest"></script>
39
- <script src="./_assets/index.js"></script>
40
- </body>
41
- </html>
package/docs/migration.md DELETED
@@ -1,202 +0,0 @@
1
- # Migration guides
2
-
3
- ## V3 to V4
4
-
5
- Vest 4.0 is a major release that contains several breaking changes. Most should be pretty simple to migrate, but there are a few things that require a bit more attention.](https://
6
-
7
- ### Removed: Default import support
8
-
9
- For better tree shaking, we removed the default import support. This means that if you need a part of the library, you will need to import it explicitly, resulting in a smaller eventual bundle size.
10
-
11
- ### V3
12
-
13
- ```js
14
- import vest from 'vest';
15
- ```
16
-
17
- ### V4
18
-
19
- ```js
20
- import * as vest from 'vest';
21
- // OR:
22
- import { create, test, enforce } from 'vest';
23
- ```
24
-
25
- ### Removed: Suite name from suite declaration
26
-
27
- From now on, suites do not accept a name when being declared. The name used to serve a purpose in V2 when accessing properties from the suite, but it serves no purpose anymore.
28
-
29
- #### V3
30
-
31
- ```js
32
- import { create } from 'vest';
33
-
34
- create('my-suite', () => {});
35
- ```
36
-
37
- ### V4
38
-
39
- ```js
40
- import { create } from 'vest';
41
-
42
- create(() => {});
43
- ```
44
-
45
- ### Renamed: classNames to classnames
46
-
47
- Vest 3 included the `vest/classNames` import. It is now renamed to `vest/classnames`.
48
-
49
- ### V3
50
-
51
- ```js
52
- import classNames from 'vest/classNames';
53
- ```
54
-
55
- ### V4
56
-
57
- ```js
58
- import classnames from 'vest/classnames';
59
- ```
60
-
61
- ### Changed: Do not use if/else statements to conditionally run tests
62
-
63
- Vest version 4 relies on order of execution and remembers the result of each test based on its location in the suite, similar to the way [hooks in react](https://reactjs.org/docs/hooks-rules.html) work. This means that tests wrapped in an if/else statement make Vest go out of sync with the suite order, and unexecuted test results will be recorded. Instead of using if/else statements, you should use the `skipWhen` function that achieves the same result.
64
-
65
- ### V3
66
-
67
- ```js
68
- if (!suite.get().hasErrors('password')) {
69
- test('confirm', 'passwords do not match', () => {
70
- /*...*/
71
- });
72
- }
73
- ```
74
-
75
- ### V4
76
-
77
- ```js
78
- import { skipWhen, test } from 'vest';
79
-
80
- // ...
81
-
82
- skipWhen(suite.hasErrors('password'), () => {
83
- test('confirm', 'passwords do not match', () => {
84
- /*...*/
85
- });
86
- });
87
-
88
- // ...
89
- ```
90
-
91
- **Note**
92
- If you want to completely omit a test from your suite, and you know that it won't appear at all during the lifetime of your suite, you may use `if/else`.
93
-
94
- ### Removed: enforce.template
95
-
96
- enforce.template was mostly a shorthand for a "and" style enforcements. In reality it did not provide any substantial functionality that was not achievable without it, while it contributed to confusion regarding the api.
97
-
98
- ## V2 to V3
99
-
100
- Vest version 3 comes with many new features, yet with a reduced bundle size. To achieve this, some redundant interfaces were removed. All v2 capabilities still exist, but the way to use some of them changed.
101
-
102
- **Replaced interfaces**
103
-
104
- ### Removed: vest.get()
105
-
106
- From now on, use suite.get() to get the latest validation result.
107
-
108
- #### v2
109
-
110
- ```js
111
- const suite = vest.create('user_form', () => {
112
- /*...*/
113
- });
114
-
115
- vest.get('user_form'); // Returns the most recent validation result
116
- ```
117
-
118
- #### v3
119
-
120
- ```js
121
- const suite = create(() => {
122
- /*...*/
123
- });
124
-
125
- suite.get(); // Returns the most recent validation result
126
- ```
127
-
128
- ### Removed: vest.reset() // To reset suite state
129
-
130
- From now on, use suite.reset() to reset the validation result.
131
-
132
- #### v2
133
-
134
- ```js
135
- const suite = vest.create('user_form', () => {
136
- /*...*/
137
- });
138
-
139
- vest.reset('user_form'); // Resets the validity state
140
- ```
141
-
142
- #### v3
143
-
144
- ```js
145
- const suite = create(() => {
146
- /*...*/
147
- });
148
-
149
- suite.reset(); // Resets the validity state
150
- ```
151
-
152
- ### Removed: vest.draft() // To retrieve intermediate result
153
-
154
- From now on, use suite.get() to get the validation result.
155
-
156
- #### v2
157
-
158
- ```js
159
- const suite = vest.create('user_form', () => {
160
- if (vest.draft().hasErrors('username')) {
161
- /* ... */
162
- }
163
- });
164
- ```
165
-
166
- #### v3
167
-
168
- ```js
169
- const suite = create('user_form', () => {
170
- if (suite.get().hasErrors('username')) {
171
- /* ... */
172
- }
173
- });
174
- ```
175
-
176
- ### Removed: validate() // For non persistent validations
177
-
178
- The stateless validate export is not needed anymore due to a change in the state structure.
179
-
180
- #### v2
181
-
182
- ```js
183
- import { validate } from 'vest';
184
-
185
- const result = data =>
186
- validate('user_form', () => {
187
- /*...*/
188
- })();
189
- ```
190
-
191
- #### v3
192
-
193
- ```js
194
- import { create } from 'vest';
195
-
196
- const suite = data =>
197
- create(() => {
198
- /* ... */
199
- })();
200
-
201
- const result = suite({ username: 'example' });
202
- ```