1 | const assert = require('assert');
|
2 |
|
3 | const { Validator, bailable } = require('../lib/index');
|
4 |
|
5 |
|
6 | describe('Non bailable', () => {
|
7 | it('should return multiple errors', async () => {
|
8 |
|
9 | const v = new Validator(
|
10 | { name: '12' },
|
11 | {
|
12 | name: ['required', ['minLength', '5'], ['maxLength', '10'], 'alpha'],
|
13 | },
|
14 | );
|
15 |
|
16 | v.bail(false);
|
17 |
|
18 | const matched = await v.check();
|
19 |
|
20 | assert.equal(matched, false);
|
21 | assert.equal(Array.isArray(v.errors.name), true);
|
22 | });
|
23 |
|
24 | it('should toggle multiple errors on current instance', async () => {
|
25 |
|
26 | const v = new Validator(
|
27 | { name: '12' },
|
28 | {
|
29 | name: ['required', ['minLength', '5'], ['maxLength', '10'], 'alpha'],
|
30 | },
|
31 | );
|
32 |
|
33 | v.bail(false);
|
34 |
|
35 | const matched = await v.check();
|
36 |
|
37 | assert.equal(matched, false);
|
38 | assert.equal(Array.isArray(v.errors.name), true);
|
39 |
|
40 | v.bail(true);
|
41 |
|
42 | const matchedAgain = await v.check();
|
43 |
|
44 | assert.equal(matchedAgain, false);
|
45 | assert.equal(!Array.isArray(v.errors.name), true);
|
46 | });
|
47 |
|
48 | it('should toggle multiple errors', async () => {
|
49 |
|
50 | bailable(false);
|
51 | const v = new Validator(
|
52 | { name: 'art' },
|
53 | {
|
54 | name: ['required', ['minLength', '5'], ['maxLength', '10'], 'alpha'],
|
55 | },
|
56 | );
|
57 |
|
58 |
|
59 | assert.equal(v.breakWhenFailed, false);
|
60 |
|
61 |
|
62 | bailable(true);
|
63 |
|
64 |
|
65 | assert.equal(v.breakWhenFailed, false);
|
66 |
|
67 |
|
68 | v.bail(true);
|
69 |
|
70 |
|
71 | assert.equal(v.breakWhenFailed, true);
|
72 | });
|
73 | });
|