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: rc1
Date: 4 months ago
Size: 1,310 bytes
 

Contents

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

const Validator = require('../../index');


describe('nullable', function () {


    it('should fail', async () => {

        const v = new Validator(
            { attribute: "email" },
            { attribute: 'nullable|email' });

        const matched = await v.check();

        assert.equal(matched, false);

        //assert.equal(v.errors.attribute.message, v.parseExistingMessageOnly('nullable', 'attribute', '',4));

    });

    it('attribute absent, should fail', async () => {

        let v, matched;

        v = new Validator(
            { },
            { attribute: 'nullable|email' });

        matched = await v.check();

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


    it('should pass', async () => {

        let v, matched;

        v = new Validator(
            { attribute: null },
            { attribute: 'nullable|email' });

        matched = await v.check();

        console.log(v.errors);

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

    it('should pass', async () => {

        let v, matched;

        v = new Validator(
            { attribute: null },
            { attribute: 'nullable|alpha|required' });

        matched = await v.check();

        console.log(v.errors);

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



});