UNPKG

vanilla-validation

Version:

Vanilla JavaScript validation rules

52 lines (34 loc) 1.81 kB
const jsdom = require("jsdom"); const { JSDOM } = jsdom; describe("vrule_minValue", function() { var vRules = require('../src/utilities/form-validation'); console.log("testing: vrule_minValue") it("should return error message - minvalue - 1", function() { const dom = new JSDOM(`<!DOCTYPE html><input value="1" id="test">`); let dummyInput = dom.window.document.getElementById("test") expect(vRules.vrule_minValue(dummyInput, 10).message) .toBe("This field requires minimum value of 10") }); it("should return error message - minvalue - a", function() { const dom = new JSDOM(`<!DOCTYPE html><input value="a" id="test">`); let dummyInput = dom.window.document.getElementById("test") expect(vRules.vrule_minValue(dummyInput, 10).message) .toBe("This field requires minimum value of 10") }); it("should return error message - minvalue - £1", function() { const dom = new JSDOM(`<!DOCTYPE html><input value="£1" id="test">`); let dummyInput = dom.window.document.getElementById("test") expect(vRules.vrule_minValue(dummyInput, 10).message) .toBe("This field requires minimum value of 10") }); 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_minValue(dummyInput, 10).message).not.toBeDefined(); }); it("should pass validation", function() { const dom = new JSDOM(`<!DOCTYPE html><input value="20" id="test">`); let dummyInput = dom.window.document.getElementById("test") expect(vRules.vrule_minValue(dummyInput, 10).message).not.toBeDefined(); }); });