UNPKG

vanilla-validation

Version:

Vanilla JavaScript validation rules

35 lines (22 loc) 1.13 kB
const jsdom = require("jsdom"); const { JSDOM } = jsdom; describe("vrule_minLength", function() { var vRules = require('../src/utilities/form-validation'); console.log("testing: vrule_minLength") it("should return error message - minlength - 1", function() { const dom = new JSDOM(`<!DOCTYPE html><input value="a" id="test">`); let dummyInput = dom.window.document.getElementById("test") expect(vRules.vrule_minLength(dummyInput, 3).message) .toBe("This field requires atleast 3 characters") }); it("should pass validation - empty", function() { const dom = new JSDOM(`<!DOCTYPE html><input value="" id="test">`); let dummyInput = dom.window.document.getElementById("test") expect(vRules.vrule_minLength(dummyInput, 3).message).not.toBeDefined(); }); it("should pass validation", function() { const dom = new JSDOM(`<!DOCTYPE html><input value="abcd" id="test">`); let dummyInput = dom.window.document.getElementById("test") expect(vRules.vrule_minLength(dummyInput, 3).message).not.toBeDefined(); }); });