Icontem

File: test/rules/dateAfter.js

Recommend this page to a friend!
  Classes of Harcharan Singh  >  Node Input Validator  >  test/rules/dateAfter.js  >  Download  
File: test/rules/dateAfter.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: nxt
Date: 5 months ago
Size: 1,251 bytes
 

Contents

Class file image Download
const assert = require('assert');
const { Validator } = require('../../lib/index');

describe('#dateAfter', () => {
  it('should pass with validadate format', async () => {
    const v = new Validator(
      { dob: '1990-02-28' },
      { dob: 'required|dateFormat:YYYY-MM-DD|dateAfter:1990-01-01' },
    );

    const matched = await v.check();
    assert.equal(matched, true);
  });


  it('should fail with invalida date format', async () => {
    let v = new Validator({ dob: '1993-28-02' }, { dob: 'required|dateFormat:YYYY-MM-DD|dateAfter:2000-15-31' });

    let matched = await v.check();

    assert.equal(matched, false);

    v = new Validator({ dob: '1993-28-02' }, { dob: 'required|dateFormat:YYYY-MM-DD|after:2000-12-31' });

    matched = await v.check();

    assert.equal(matched, false);
  });

  it('message should exist', async () => {
    const v = new Validator({ dob: '1993-10-15' }, { dob: 'required|dateFormat:YYYY-MM-DD|after:2000-12-31' });

    const matched = await v.check();

    assert.equal(matched, false);
    assert.equal(
      v.errors.dob.message,
      v.getExistinParsedMessage({
        rule: 'after',
        value: '1993-10-15',
        attr: 'dob',
        args: ['2000-12-31'],
      }),
    );
  });
});