Icontem

File: test/rules/nullable.js

Recommend this page to a friend!
  Classes of Harcharan Singh  >  Node Input Validator  >  test/rules/nullable.js  >  Download  
File: test/rules/nullable.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Node Input Validator
Validate submitted input values in Node.js
Author: By
Last change: nxt
Date: 9 months ago
Size: 1,000 bytes
 

Contents

Class file image Download
const assert = require('assert');

const { Validator } = require('../../lib/index');


describe('nullable', () => {
  it('should fail', async () => {
    const v = new Validator(
      { attr: 'email' },
      { attr: 'nullable|email' },
    );

    const matched = await v.check();

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

  it('should fail, attr absent', async () => {
    const v = new Validator(
      {},
      { attr: 'nullable|email' },
    );

    const matched = await v.check();

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


  it('should pass, attr is null', async () => {
    const v = new Validator(
      { attr: null },
      { attr: 'nullable|email' },
    );

    const matched = await v.check();

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

  it('should pass, attr is null, ignore required', async () => {
    const v = new Validator(
      { attr: null },
      { attr: 'nullable|alpha|required' },
    );

    const matched = await v.check();

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