File: test/rules/accepted.js

Recommend this page to a friend!
  Classes of Harcharan Singh   Node Input Validator   test/rules/accepted.js   Download  
File: test/rules/accepted.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: Update of test/rules/accepted.js
Date: 2 years ago
Size: 1,137 bytes
 

Contents

Class file image Download
const assert = require('assert'); const { Validator } = require('../../lib/index'); describe('accepted', () => { it('should pass with yes', async () => { const v = new Validator( { attr: 'yes' }, { attr: 'accepted' }, ); const matched = await v.check(); assert.equal(matched, true); }); it('should pass with ok using custom options', async () => { const v = new Validator( { attr: 'ok' }, { attr: 'accepted:ok' }, ); const matched = await v.check(); assert.equal(matched, true); }); it('should fail using no', async () => { const v = new Validator( { attr: 'no' }, { attr: 'accepted' }, ); const matched = await v.check(); assert.equal(matched, false); }); it('message should exist', async () => { const v = new Validator( {}, { attr: 'accepted' }, ); const matched = await v.check(); assert.equal(matched, false); assert.equal( v.errors.attr.message, v.getExistinParsedMessage({ rule: 'accepted', value: undefined, attr: 'attr', }), ); }); });