Icontem

File: test/rules/required.js

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

Contents

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


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

describe('requiredRules', function () {

    describe('#required', function () {

        it('should return true', async () => {

            let v = new Validator({ name: 'Harcharan Singh' }, { name: 'required' });

            let matched = await v.check();

            assert.equal(matched, true);

        });

        it('should return false', async () => {

            let v = new Validator({ name: '' }, { name: 'required' });

            let matched = await v.check();

            assert.equal(matched, false);

        });

        it('should return false', async () => {

            let v = new Validator({ name: '' }, { name: 'required|min:1' });

            let matched = await v.check();

            assert.equal(matched, false);

        });

        it('should return false', async () => {

            let v = new Validator({ email: '' }, { name: 'required|email' });

            let matched = await v.check();

            assert.equal(matched, false);

            assert.equal(v.errors.name.message, v.parseExistingMessageOnly('required', 'name', '',4));

        });

    });
});