UNPKG

893 BJavaScriptView Raw
1const assert = require('assert');
2
3const { Validator } = require('../../lib/index');
4
5describe('function', () => {
6 it('should use custom function', async () => {
7 let v = new Validator({ username: 'arnold', password: 'arnold123' }, {});
8
9 v.addPostRule(async (provider) => {
10 if (provider.inputs.password.indexOf(provider.inputs.username) >= 0) {
11 provider.error('password', 'custom', 'Password cannot contain username');
12 }
13 });
14
15 let matched = await v.check();
16
17 assert.equal(matched, false);
18
19 v = new Validator({ username: 'arnold', password: '123456' }, {});
20
21 v.addPostRule(async (provider) => {
22 if (provider.inputs.password.indexOf(provider.inputs.username) >= 0) {
23 provider.error('password', 'custom', 'Password cannot contain username');
24 }
25 });
26
27 matched = await v.check();
28
29 assert.equal(matched, true);
30 });
31});