Icontem

File: test/edge.js

Recommend this page to a friend!
  Classes of Harcharan Singh  >  Node Input Validator  >  test/edge.js  >  Download  
File: test/edge.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: v3.0.0alphs
Date: 4 months ago
Size: 1,792 bytes
 

Contents

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

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

let r = {};

describe('Edge Cases', function () {

    describe('undefined', function () {

        it('should ignore undefined and not required fields', async () => {

            let v = new Validator({ field: undefined }, { field: 'string' });

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

        });


        it('should reject undefined and required fields', async () => {

            let v = new Validator({ field: undefined }, { field: 'required|string' });

            let matched = await v.check();
            assert.equal(matched, false);

        });

    });

    describe('null', function () {

        it('should ignore null and not required fields', async () => {

            let v = new Validator({ field: null }, { field: 'string' });

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

        });


        it('should reject null and required fields', async () => {

            let v = new Validator({ field: null }, { field: 'required|string' });

            let matched = await v.check();
            assert.equal(matched, false);

        });

    });

    describe('empty string', function () {

        it('should ignore empty string in not required fields', async () => {

            let v = new Validator({ field: '' }, { field: 'string' });

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

        });


        it('should reject empty string in required fields', async () => {

            let v = new Validator({ field: '' }, { field: 'required|string' });

            let matched = await v.check();
            assert.equal(matched, false);

        });

    });

});