File: test/rules/dateFormat.js

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

Contents

Class file image Download
const assert = require('assert'); const { Validator } = require('../../lib/index'); describe('dateFormat', () => { it('should pass with valid date', async () => { const v = new Validator( { attr: '2018-12-26' }, { attr: 'dateFormat:YYYY-MM-DD' }, ); const matched = await v.passes(); assert.equal(matched, true); }); it('should pass', async () => { const v = new Validator( { attr: '2018/01/26' }, { attr: 'dateFormat:YYYY/MM/DD' }, ); const matched = await v.passes(); assert.equal(matched, true); }); it('should fail with invalid format', async () => { const v = new Validator( { attr: '12 12 18' }, { attr: 'dateFormat:YYYY-MM-DD' }, ); const matched = await v.fails(); assert.equal(matched, true); }); it('message should exist', async () => { const v = new Validator( { attr: '28/08/2019' }, { attr: 'dateFormat:YYYY-MM-DD' }, ); const matched = await v.fails(); assert.equal(matched, true); assert.equal( v.errors.attr.message, v.getExistinParsedMessage({ rule: 'dateFormat', value: '28/08/2019', attr: 'attr', args: ['YYYY-MM-DD'], }), ); }); });