This repository has been archived on 2020-11-15. You can view files and clone it, but cannot push or open issues or pull requests.
schemajs/test/required.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2012-05-28 00:35:58 +00:00
describe("required schemas", function()
2011-11-16 02:58:03 +00:00
{
/*jshint expr:true*/
var schemajs = (typeof window === 'undefined') ? require('../schema') : window.schema;
var expect = (typeof window === 'undefined') ? require('chai').expect : window.chai.expect;
2012-05-28 00:35:58 +00:00
it("required", function()
2011-11-16 02:58:03 +00:00
{
2012-05-28 00:35:58 +00:00
var schema = schemajs.create(
{
input: {type:'string', required:true},
output: {type:'string'}
2012-05-28 00:35:58 +00:00
});
var input1 = schema.validate({input: 'username'});
var input2 = schema.validate({});
2012-05-28 00:35:58 +00:00
expect(input1.valid).to.be.ok;
expect(!input2.valid).to.be.ok;
2011-11-16 02:58:03 +00:00
});
2012-10-08 00:14:35 +00:00
it("allownull", function()
{
var schema = schemajs.create(
{
input: {type:'string', required:true, allownull:true},
output:{type:'string'}
});
var input1 = schema.validate({input: 'username'});
var input2 = schema.validate({});
var input3 = schema.validate({input:null, output:"hi there"});
2012-10-08 00:14:35 +00:00
expect(input1.valid).to.be.ok;
expect(input1.data.input).to.equal('username');
2012-10-08 00:14:35 +00:00
expect(!input2.valid).to.be.ok;
expect(input3.valid).to.be.ok;
expect(input3.data.input).to.equal(null);
2012-10-08 00:14:35 +00:00
});
2011-11-16 02:58:03 +00:00
});