Icontem

File: test/rules/dateBefore.js

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

Contents

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

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

    const matched = await v.fails();
    assert.equal(matched, false);
  });

  it('should fail', async () => {
    const v = new Validator({ dob: '1993-28-02' }, { dob: 'required|dateFormat:YYYY-MM-DD|dateBefore:1992-12-31' });

    const matched = await v.passes();

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

  it('message should exist', async () => {
    const v = new Validator({ dob: '1993-02-28' }, { dob: 'required|dateFormat:YYYY-MM-DD|before:1992-12-31' });

    const matched = await v.passes();

    assert.equal(matched, false);
    assert.equal(
      v.errors.dob.message,
      v.getExistinParsedMessage({
        rule: 'dateBefore',
        value: '1992-12-31',
        attr: 'dob',
        args: ['1992-12-31'],
      }),
    );
  });
});