File: test/rules/different.js

Recommend this page to a friend!
  Classes of Harcharan Singh   Node Input Validator   test/rules/different.js   Download  
File: test/rules/different.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Node Input Validator
Validate submitted input values in Node.js
Author: By
Last change:
Date: 2 years ago
Size: 1,180 bytes
 

Contents

Class file image Download
const assert = require('assert'); const { Validator } = require('../../lib/index'); describe('different', () => { it('should pass', async () => { const v = new Validator( { password: '000000', new_password: '123456' }, { password: 'required', new_password: 'required|different:password' }, ); const matched = await v.check(); assert.equal(matched, true); }); it('should fail', async () => { const v = new Validator( { password: '000000', new_password: '000000' }, { password: 'required', new_password: 'required|different:password' }, ); const matched = await v.check(); assert.equal(matched, false); }); it('message should exist', async () => { const v = new Validator( { password: '000000', new_password: '000000' }, { password: 'required', new_password: 'required|different:password' }, ); const matched = await v.check(); assert.equal(matched, false); assert.equal( v.errors.new_password.message, v.getExistinParsedMessage({ rule: 'different', value: '', attr: 'new_password', args: ['password'], }), ); }); });