joi 4.6.2 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c9/.nakignore +17 -0
- package/.c9/metadata/tab0 +1 -0
- package/.c9/metadata/workspace/.c9/project.settings +1 -0
- package/.c9/metadata/workspace/.travis.yml +1 -0
- package/.c9/metadata/workspace/Makefile +1 -0
- package/.c9/metadata/workspace/README.md +1 -0
- package/.c9/metadata/workspace/lib/any.js +1 -0
- package/.c9/metadata/workspace/lib/array.js +1 -0
- package/.c9/metadata/workspace/lib/binary.js +1 -0
- package/.c9/metadata/workspace/lib/boolean.js +1 -0
- package/.c9/metadata/workspace/lib/cast.js +1 -0
- package/.c9/metadata/workspace/lib/date.js +1 -0
- package/.c9/metadata/workspace/lib/errors.js +1 -0
- package/.c9/metadata/workspace/lib/function.js +1 -0
- package/.c9/metadata/workspace/lib/index.js +1 -0
- package/.c9/metadata/workspace/lib/language.js +1 -0
- package/.c9/metadata/workspace/lib/number.js +1 -0
- package/.c9/metadata/workspace/lib/object.js +1 -0
- package/.c9/metadata/workspace/lib/string.js +1 -0
- package/.c9/metadata/workspace/package.json +1 -0
- package/.c9/metadata/workspace/test/alternatives.js +1 -0
- package/.c9/metadata/workspace/test/any.js +1 -0
- package/.c9/metadata/workspace/test/array.js +1 -0
- package/.c9/metadata/workspace/test/binary.js +1 -0
- package/.c9/metadata/workspace/test/boolean.js +1 -0
- package/.c9/metadata/workspace/test/date.js +1 -0
- package/.c9/metadata/workspace/test/errors.js +1 -0
- package/.c9/metadata/workspace/test/function.js +1 -0
- package/.c9/metadata/workspace/test/helper.js +1 -0
- package/.c9/metadata/workspace/test/index.js +1 -0
- package/.c9/metadata/workspace/test/number.js +1 -0
- package/.c9/metadata/workspace/test/object.js +1 -0
- package/.c9/metadata/workspace/test/ref.js +1 -0
- package/.c9/metadata/workspace/test/string.js +1 -0
- package/.c9/project.settings +34 -0
- package/.travis.yml +1 -0
- package/Makefile +3 -3
- package/README.md +162 -31
- package/examples/conditionalRequire.js +43 -0
- package/examples/customMessage.js +22 -0
- package/examples/multipleWhen.js +17 -0
- package/lib/any.js +35 -24
- package/lib/array.js +25 -0
- package/lib/date.js +64 -9
- package/lib/errors.js +18 -2
- package/lib/index.js +3 -2
- package/lib/language.js +17 -6
- package/lib/number.js +50 -0
- package/lib/object.js +69 -5
- package/lib/string.js +27 -6
- package/package.json +5 -3
- package/test/alternatives.js +12 -10
- package/test/any.js +64 -15
- package/test/array.js +55 -16
- package/test/binary.js +13 -11
- package/test/boolean.js +9 -7
- package/test/date.js +143 -20
- package/test/errors.js +26 -15
- package/test/function.js +7 -5
- package/test/helper.js +7 -5
- package/test/index.js +116 -73
- package/test/number.js +125 -12
- package/test/object.js +192 -43
- package/test/ref.js +22 -20
- package/test/string.js +255 -106
- package/AUTHORS +0 -3
package/test/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Load modules
|
|
2
2
|
|
|
3
3
|
var Lab = require('lab');
|
|
4
|
+
var Code = require('code');
|
|
4
5
|
var Path = require('path');
|
|
5
6
|
var Joi = require('../lib');
|
|
7
|
+
var Helper = require('./helper');
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
// Declare internals
|
|
@@ -12,12 +14,12 @@ var internals = {};
|
|
|
12
14
|
|
|
13
15
|
// Test shortcuts
|
|
14
16
|
|
|
15
|
-
var
|
|
16
|
-
var before =
|
|
17
|
-
var after =
|
|
18
|
-
var describe =
|
|
19
|
-
var it =
|
|
20
|
-
var
|
|
17
|
+
var lab = exports.lab = Lab.script();
|
|
18
|
+
var before = lab.before;
|
|
19
|
+
var after = lab.after;
|
|
20
|
+
var describe = lab.describe;
|
|
21
|
+
var it = lab.it;
|
|
22
|
+
var expect = Code.expect;
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
describe('Joi', function () {
|
|
@@ -38,7 +40,7 @@ describe('Joi', function () {
|
|
|
38
40
|
|
|
39
41
|
schema.validate(obj, function (err, value) {
|
|
40
42
|
|
|
41
|
-
expect(err).to.not.exist;
|
|
43
|
+
expect(err).to.not.exist();
|
|
42
44
|
done();
|
|
43
45
|
});
|
|
44
46
|
});
|
|
@@ -67,7 +69,7 @@ describe('Joi', function () {
|
|
|
67
69
|
|
|
68
70
|
Joi.string().validate(null, function (err, value) {
|
|
69
71
|
|
|
70
|
-
expect(err).to.exist;
|
|
72
|
+
expect(err).to.exist();
|
|
71
73
|
expect(err.annotate()).to.equal('{\n \u001b[41m\"value\"\u001b[0m\u001b[31m [1]: -- missing --\u001b[0m\n}\n\u001b[31m\n[1] value must be a string\u001b[0m');
|
|
72
74
|
done();
|
|
73
75
|
});
|
|
@@ -151,10 +153,10 @@ describe('Joi', function () {
|
|
|
151
153
|
|
|
152
154
|
Joi.compile(/^5$/).validate('5', function (err, value) {
|
|
153
155
|
|
|
154
|
-
expect(err).to.not.exist;
|
|
156
|
+
expect(err).to.not.exist();
|
|
155
157
|
Joi.compile(/.{2}/).validate('6', function (err, value) {
|
|
156
158
|
|
|
157
|
-
expect(err).to.exist;
|
|
159
|
+
expect(err).to.exist();
|
|
158
160
|
done();
|
|
159
161
|
});
|
|
160
162
|
});
|
|
@@ -357,6 +359,38 @@ describe('Joi', function () {
|
|
|
357
359
|
});
|
|
358
360
|
});
|
|
359
361
|
|
|
362
|
+
it('validates nand()', function (done) {
|
|
363
|
+
|
|
364
|
+
var schema = Joi.object({
|
|
365
|
+
txt: Joi.string(),
|
|
366
|
+
upc: Joi.string().allow(null, ''),
|
|
367
|
+
code: Joi.number()
|
|
368
|
+
}).nand('txt', 'upc', 'code');
|
|
369
|
+
|
|
370
|
+
Joi.validate({ txt: 'x', upc: 'y', code: 123 }, schema, { abortEarly: false }, function (err, value) {
|
|
371
|
+
|
|
372
|
+
expect(err.message).to.equal('value txt must not exist simultaneously with upc, code');
|
|
373
|
+
|
|
374
|
+
Helper.validate(schema, [
|
|
375
|
+
[{}, true],
|
|
376
|
+
[{ upc: null }, true],
|
|
377
|
+
[{ upc: 'test' }, true],
|
|
378
|
+
[{ txt: 'test' }, true],
|
|
379
|
+
[{ code: 123 }, true],
|
|
380
|
+
[{ txt: 'test', upc: null }, true],
|
|
381
|
+
[{ txt: 'test', upc: '' }, true],
|
|
382
|
+
[{ txt: undefined, upc: 'test' }, true],
|
|
383
|
+
[{ txt: 'test', upc: undefined }, true],
|
|
384
|
+
[{ txt: 'test', upc: '' }, true],
|
|
385
|
+
[{ txt: 'test', upc: null }, true],
|
|
386
|
+
[{ txt: 'test', upc: undefined, code: 999 }, true],
|
|
387
|
+
[{ txt: 'test', upc: 'test' }, true],
|
|
388
|
+
[{ txt: 'test', upc: 'test', code: 322 }, false],
|
|
389
|
+
[{ txt: 'test', upc: null, code: 322 }, false]
|
|
390
|
+
], done);
|
|
391
|
+
});
|
|
392
|
+
});
|
|
393
|
+
|
|
360
394
|
it('validates an array of valid types', function (done) {
|
|
361
395
|
|
|
362
396
|
var schema = Joi.object({
|
|
@@ -371,7 +405,7 @@ describe('Joi', function () {
|
|
|
371
405
|
|
|
372
406
|
schema.validate({ auth: { mode: 'none' } }, function (err, value) {
|
|
373
407
|
|
|
374
|
-
expect(err).to.exist;
|
|
408
|
+
expect(err).to.exist();
|
|
375
409
|
expect(err.message).to.equal('mode must be one of required, optional, try, null. auth must be a string. auth must be a boolean');
|
|
376
410
|
|
|
377
411
|
Helper.validate(schema, [
|
|
@@ -401,7 +435,7 @@ describe('Joi', function () {
|
|
|
401
435
|
|
|
402
436
|
schema.validate({ auth: { mode: 'none' } }, function (err, value) {
|
|
403
437
|
|
|
404
|
-
expect(err).to.exist;
|
|
438
|
+
expect(err).to.exist();
|
|
405
439
|
expect(err.message).to.equal('mode must be one of required, optional, try, null. auth must be a string. auth must be a boolean');
|
|
406
440
|
|
|
407
441
|
Helper.validate(schema, [
|
|
@@ -493,7 +527,7 @@ describe('Joi', function () {
|
|
|
493
527
|
|
|
494
528
|
schema.validate(obj, function (err, value) {
|
|
495
529
|
|
|
496
|
-
expect(err).to.exist;
|
|
530
|
+
expect(err).to.exist();
|
|
497
531
|
expect(value.a).to.equal('5');
|
|
498
532
|
done();
|
|
499
533
|
});
|
|
@@ -509,7 +543,7 @@ describe('Joi', function () {
|
|
|
509
543
|
|
|
510
544
|
schema.validate(obj, function (err, value) {
|
|
511
545
|
|
|
512
|
-
expect(err).to.not.exist;
|
|
546
|
+
expect(err).to.not.exist();
|
|
513
547
|
expect(value.hasOwnProperty('a')).to.equal(false);
|
|
514
548
|
done();
|
|
515
549
|
});
|
|
@@ -534,7 +568,7 @@ describe('Joi', function () {
|
|
|
534
568
|
|
|
535
569
|
schema.validate({ username: 'bob' }, function (err, value) {
|
|
536
570
|
|
|
537
|
-
expect(err).to.exist;
|
|
571
|
+
expect(err).to.exist();
|
|
538
572
|
done();
|
|
539
573
|
});
|
|
540
574
|
});
|
|
@@ -543,10 +577,10 @@ describe('Joi', function () {
|
|
|
543
577
|
|
|
544
578
|
Joi.boolean().allow(null).validate(true, function (err, value) {
|
|
545
579
|
|
|
546
|
-
expect(err).to.be.null;
|
|
580
|
+
expect(err).to.be.null();
|
|
547
581
|
Joi.object().validate({ auth: { mode: 'try' } }, function (err, value) {
|
|
548
582
|
|
|
549
|
-
expect(err).to.be.null;
|
|
583
|
+
expect(err).to.be.null();
|
|
550
584
|
|
|
551
585
|
Joi.object().validate(true, function (err, value) {
|
|
552
586
|
|
|
@@ -558,10 +592,10 @@ describe('Joi', function () {
|
|
|
558
592
|
|
|
559
593
|
Joi.string().email().validate('test@test.com', function (err, value) {
|
|
560
594
|
|
|
561
|
-
expect(err).to.be.null;
|
|
595
|
+
expect(err).to.be.null();
|
|
562
596
|
Joi.object({ param: Joi.string().required() }).validate({ param: 'item' }, function (err, value) {
|
|
563
597
|
|
|
564
|
-
expect(err).to.be.null;
|
|
598
|
+
expect(err).to.be.null();
|
|
565
599
|
done();
|
|
566
600
|
});
|
|
567
601
|
});
|
|
@@ -580,7 +614,7 @@ describe('Joi', function () {
|
|
|
580
614
|
var input = { a: '5' };
|
|
581
615
|
schema.validate(input, function (err, value) {
|
|
582
616
|
|
|
583
|
-
expect(err).to.be.null;
|
|
617
|
+
expect(err).to.be.null();
|
|
584
618
|
expect(value.a).to.equal(5);
|
|
585
619
|
expect(input.a).to.equal('5');
|
|
586
620
|
done();
|
|
@@ -591,7 +625,7 @@ describe('Joi', function () {
|
|
|
591
625
|
|
|
592
626
|
Joi.object().validate({ foo: 'bar' }, function (err, value) {
|
|
593
627
|
|
|
594
|
-
expect(err).to.not.exist;
|
|
628
|
+
expect(err).to.not.exist();
|
|
595
629
|
done();
|
|
596
630
|
});
|
|
597
631
|
});
|
|
@@ -600,17 +634,17 @@ describe('Joi', function () {
|
|
|
600
634
|
|
|
601
635
|
Joi.object({}).validate({ foo: 'bar' }, function (err, value) {
|
|
602
636
|
|
|
603
|
-
expect(err).to.exist;
|
|
637
|
+
expect(err).to.exist();
|
|
604
638
|
expect(err.message).to.equal('foo is not allowed');
|
|
605
639
|
|
|
606
640
|
Joi.compile({}).validate({ foo: 'bar' }, function (err, value) {
|
|
607
641
|
|
|
608
|
-
expect(err).to.exist;
|
|
642
|
+
expect(err).to.exist();
|
|
609
643
|
expect(err.message).to.equal('foo is not allowed');
|
|
610
644
|
|
|
611
645
|
Joi.compile({ other: Joi.number() }).validate({ foo: 'bar' }, function (err, value) {
|
|
612
646
|
|
|
613
|
-
expect(err).to.exist;
|
|
647
|
+
expect(err).to.exist();
|
|
614
648
|
expect(err.message).to.equal('foo is not allowed');
|
|
615
649
|
|
|
616
650
|
done();
|
|
@@ -629,12 +663,12 @@ describe('Joi', function () {
|
|
|
629
663
|
|
|
630
664
|
Joi.compile(config).validate({ auth: { unknown: true } }, function (err, value) {
|
|
631
665
|
|
|
632
|
-
expect(err).to.not.be.null;
|
|
666
|
+
expect(err).to.not.be.null();
|
|
633
667
|
expect(err.message).to.contain('unknown is not allowed');
|
|
634
668
|
|
|
635
669
|
Joi.compile(config).validate({ something: false }, function (err, value) {
|
|
636
670
|
|
|
637
|
-
expect(err).to.not.be.null;
|
|
671
|
+
expect(err).to.not.be.null();
|
|
638
672
|
expect(err.message).to.contain('something is not allowed');
|
|
639
673
|
|
|
640
674
|
done();
|
|
@@ -656,22 +690,22 @@ describe('Joi', function () {
|
|
|
656
690
|
|
|
657
691
|
Joi.compile(config).validate({}, function (err, value) {
|
|
658
692
|
|
|
659
|
-
expect(err).to.exist;
|
|
693
|
+
expect(err).to.exist();
|
|
660
694
|
expect(err.message).to.contain('module is required');
|
|
661
695
|
|
|
662
696
|
Joi.compile(config).validate({ module: 'test' }, function (err, value) {
|
|
663
697
|
|
|
664
|
-
expect(err).to.be.null;
|
|
698
|
+
expect(err).to.be.null();
|
|
665
699
|
|
|
666
700
|
Joi.compile(config).validate({ module: {} }, function (err, value) {
|
|
667
701
|
|
|
668
|
-
expect(err).to.not.be.null;
|
|
702
|
+
expect(err).to.not.be.null();
|
|
669
703
|
expect(err.message).to.contain('compile is required');
|
|
670
704
|
expect(err.message).to.contain('module must be a string');
|
|
671
705
|
|
|
672
706
|
Joi.compile(config).validate({ module: { compile: function () { } } }, function (err, value) {
|
|
673
707
|
|
|
674
|
-
expect(err).to.be.null;
|
|
708
|
+
expect(err).to.be.null();
|
|
675
709
|
done();
|
|
676
710
|
});
|
|
677
711
|
});
|
|
@@ -693,7 +727,7 @@ describe('Joi', function () {
|
|
|
693
727
|
|
|
694
728
|
Joi.compile(config).validate({}, function (err, value) {
|
|
695
729
|
|
|
696
|
-
expect(err).to.not.exist;
|
|
730
|
+
expect(err).to.not.exist();
|
|
697
731
|
done();
|
|
698
732
|
});
|
|
699
733
|
});
|
|
@@ -712,7 +746,7 @@ describe('Joi', function () {
|
|
|
712
746
|
|
|
713
747
|
Joi.compile(config).validate({}, function (err, value) {
|
|
714
748
|
|
|
715
|
-
expect(err).to.exist;
|
|
749
|
+
expect(err).to.exist();
|
|
716
750
|
expect(err.message).to.contain('module is required');
|
|
717
751
|
done();
|
|
718
752
|
});
|
|
@@ -727,11 +761,11 @@ describe('Joi', function () {
|
|
|
727
761
|
|
|
728
762
|
Joi.compile(config).validate({ suggestion: 'something' }, function (err, value) {
|
|
729
763
|
|
|
730
|
-
expect(err).to.be.null;
|
|
764
|
+
expect(err).to.be.null();
|
|
731
765
|
|
|
732
766
|
Joi.compile(config).validate({ position: 1 }, function (err, value) {
|
|
733
767
|
|
|
734
|
-
expect(err).to.be.null;
|
|
768
|
+
expect(err).to.be.null();
|
|
735
769
|
done();
|
|
736
770
|
})
|
|
737
771
|
});
|
|
@@ -746,11 +780,11 @@ describe('Joi', function () {
|
|
|
746
780
|
|
|
747
781
|
Joi.compile(config).validate({ suggestion: {} }, function (err, value) {
|
|
748
782
|
|
|
749
|
-
expect(err).to.be.null;
|
|
783
|
+
expect(err).to.be.null();
|
|
750
784
|
|
|
751
785
|
Joi.compile(config).validate({ position: 1 }, function (err, value) {
|
|
752
786
|
|
|
753
|
-
expect(err).to.be.null;
|
|
787
|
+
expect(err).to.be.null();
|
|
754
788
|
done();
|
|
755
789
|
});
|
|
756
790
|
});
|
|
@@ -770,7 +804,7 @@ describe('Joi', function () {
|
|
|
770
804
|
|
|
771
805
|
Joi.compile(schema).validate(obj, function (err, value) {
|
|
772
806
|
|
|
773
|
-
expect(err).to.not.exist;
|
|
807
|
+
expect(err).to.not.exist();
|
|
774
808
|
done();
|
|
775
809
|
});
|
|
776
810
|
});
|
|
@@ -790,7 +824,7 @@ describe('Joi', function () {
|
|
|
790
824
|
|
|
791
825
|
Joi.compile(schema).validate(obj, function (err, value) {
|
|
792
826
|
|
|
793
|
-
expect(err).to.not.exist;
|
|
827
|
+
expect(err).to.not.exist();
|
|
794
828
|
done();
|
|
795
829
|
});
|
|
796
830
|
});
|
|
@@ -811,7 +845,7 @@ describe('Joi', function () {
|
|
|
811
845
|
|
|
812
846
|
Joi.compile(schema).validate(obj, function (err, value) {
|
|
813
847
|
|
|
814
|
-
expect(err).to.exist;
|
|
848
|
+
expect(err).to.exist();
|
|
815
849
|
done();
|
|
816
850
|
});
|
|
817
851
|
});
|
|
@@ -832,7 +866,7 @@ describe('Joi', function () {
|
|
|
832
866
|
|
|
833
867
|
Joi.compile(schema).validate(obj, function (err, value) {
|
|
834
868
|
|
|
835
|
-
expect(err).to.exist;
|
|
869
|
+
expect(err).to.exist();
|
|
836
870
|
done();
|
|
837
871
|
});
|
|
838
872
|
});
|
|
@@ -845,7 +879,7 @@ describe('Joi', function () {
|
|
|
845
879
|
|
|
846
880
|
Joi.compile({ a: Joi.string().required() }).validate(obj, function (err, value) {
|
|
847
881
|
|
|
848
|
-
expect(err).to.exist;
|
|
882
|
+
expect(err).to.exist();
|
|
849
883
|
done();
|
|
850
884
|
});
|
|
851
885
|
});
|
|
@@ -858,7 +892,7 @@ describe('Joi', function () {
|
|
|
858
892
|
|
|
859
893
|
Joi.compile({ a: Joi.object({ b: Joi.string().required() }) }).validate(obj, function (err, value) {
|
|
860
894
|
|
|
861
|
-
expect(err).to.exist;
|
|
895
|
+
expect(err).to.exist();
|
|
862
896
|
done();
|
|
863
897
|
});
|
|
864
898
|
});
|
|
@@ -871,7 +905,7 @@ describe('Joi', function () {
|
|
|
871
905
|
|
|
872
906
|
Joi.compile({ a: Joi.object({ b: Joi.string().required() }) }).validate(obj, function (err, value) {
|
|
873
907
|
|
|
874
|
-
expect(err).to.exist;
|
|
908
|
+
expect(err).to.exist();
|
|
875
909
|
done();
|
|
876
910
|
});
|
|
877
911
|
});
|
|
@@ -890,7 +924,7 @@ describe('Joi', function () {
|
|
|
890
924
|
|
|
891
925
|
Joi.validate(input, schema, function (err, value) {
|
|
892
926
|
|
|
893
|
-
expect(err).to.not.exist;
|
|
927
|
+
expect(err).to.not.exist();
|
|
894
928
|
expect(input.a).to.equal('{"b":"string"}');
|
|
895
929
|
expect(value.a.b).to.equal('string');
|
|
896
930
|
done();
|
|
@@ -905,7 +939,7 @@ describe('Joi', function () {
|
|
|
905
939
|
|
|
906
940
|
Joi.object({ a: Joi.object({ b: Joi.string().required() }) }).validate(obj, function (err, value) {
|
|
907
941
|
|
|
908
|
-
expect(err).to.exist;
|
|
942
|
+
expect(err).to.exist();
|
|
909
943
|
done();
|
|
910
944
|
});
|
|
911
945
|
});
|
|
@@ -918,7 +952,7 @@ describe('Joi', function () {
|
|
|
918
952
|
|
|
919
953
|
Joi.object({ a: Joi.array() }).validate(obj, function (err, value) {
|
|
920
954
|
|
|
921
|
-
expect(err).to.exist;
|
|
955
|
+
expect(err).to.exist();
|
|
922
956
|
done();
|
|
923
957
|
});
|
|
924
958
|
});
|
|
@@ -931,7 +965,7 @@ describe('Joi', function () {
|
|
|
931
965
|
|
|
932
966
|
Joi.object({ a: Joi.array() }).validate(obj, function (err, value) {
|
|
933
967
|
|
|
934
|
-
expect(err).to.be.null;
|
|
968
|
+
expect(err).to.be.null();
|
|
935
969
|
done();
|
|
936
970
|
});
|
|
937
971
|
});
|
|
@@ -944,7 +978,7 @@ describe('Joi', function () {
|
|
|
944
978
|
|
|
945
979
|
Joi.object({ a: Joi.object({ b: Joi.string().required() }) }).validate(obj, function (err, value) {
|
|
946
980
|
|
|
947
|
-
expect(err).to.exist;
|
|
981
|
+
expect(err).to.exist();
|
|
948
982
|
done();
|
|
949
983
|
});
|
|
950
984
|
});
|
|
@@ -963,7 +997,7 @@ describe('Joi', function () {
|
|
|
963
997
|
|
|
964
998
|
Joi.compile(schema).validate(obj, function (err, value) {
|
|
965
999
|
|
|
966
|
-
expect(err).to.exist;
|
|
1000
|
+
expect(err).to.exist();
|
|
967
1001
|
done();
|
|
968
1002
|
});
|
|
969
1003
|
});
|
|
@@ -982,7 +1016,7 @@ describe('Joi', function () {
|
|
|
982
1016
|
|
|
983
1017
|
Joi.compile(schema).validate(obj, function (err, value) {
|
|
984
1018
|
|
|
985
|
-
expect(err).to.exist;
|
|
1019
|
+
expect(err).to.exist();
|
|
986
1020
|
done();
|
|
987
1021
|
});
|
|
988
1022
|
});
|
|
@@ -1000,7 +1034,7 @@ describe('Joi', function () {
|
|
|
1000
1034
|
|
|
1001
1035
|
Joi.compile(schema).validate(obj, function (err, value) {
|
|
1002
1036
|
|
|
1003
|
-
expect(err).to.exist;
|
|
1037
|
+
expect(err).to.exist();
|
|
1004
1038
|
done();
|
|
1005
1039
|
});
|
|
1006
1040
|
});
|
|
@@ -1013,7 +1047,7 @@ describe('Joi', function () {
|
|
|
1013
1047
|
|
|
1014
1048
|
Joi.compile(schema).validate({}, function (err, value) {
|
|
1015
1049
|
|
|
1016
|
-
expect(err).to.not.exist;
|
|
1050
|
+
expect(err).to.not.exist();
|
|
1017
1051
|
done();
|
|
1018
1052
|
});
|
|
1019
1053
|
});
|
|
@@ -1034,7 +1068,7 @@ describe('Joi', function () {
|
|
|
1034
1068
|
|
|
1035
1069
|
Joi.validate(obj, schema, { stripUnknown: true, allowUnknown: true }, function (err, value) {
|
|
1036
1070
|
|
|
1037
|
-
expect(err).to.be.null;
|
|
1071
|
+
expect(err).to.be.null();
|
|
1038
1072
|
expect(value).to.deep.equal({ a: 1, b: 'a' });
|
|
1039
1073
|
done();
|
|
1040
1074
|
});
|
|
@@ -1056,7 +1090,7 @@ describe('Joi', function () {
|
|
|
1056
1090
|
|
|
1057
1091
|
Joi.validate(obj, schema, { stripUnknown: true, abortEarly: false }, function (err, value) {
|
|
1058
1092
|
|
|
1059
|
-
expect(err).to.exist;
|
|
1093
|
+
expect(err).to.exist();
|
|
1060
1094
|
done();
|
|
1061
1095
|
});
|
|
1062
1096
|
});
|
|
@@ -1077,7 +1111,7 @@ describe('Joi', function () {
|
|
|
1077
1111
|
|
|
1078
1112
|
Joi.validate(obj, schema, { allowUnknown: true }, function (err, value) {
|
|
1079
1113
|
|
|
1080
|
-
expect(err).to.be.null;
|
|
1114
|
+
expect(err).to.be.null();
|
|
1081
1115
|
expect(value).to.deep.equal({ a: 1, b: 'a', d: 'c' });
|
|
1082
1116
|
done();
|
|
1083
1117
|
});
|
|
@@ -1098,12 +1132,12 @@ describe('Joi', function () {
|
|
|
1098
1132
|
|
|
1099
1133
|
localConfig.validate(obj, function (err, value) {
|
|
1100
1134
|
|
|
1101
|
-
expect(err).to.be.null;
|
|
1135
|
+
expect(err).to.be.null();
|
|
1102
1136
|
expect(value).to.deep.equal({ a: 1, b: 'a', d: 'c' });
|
|
1103
1137
|
|
|
1104
1138
|
localConfig.validate(value, function (err, value) {
|
|
1105
1139
|
|
|
1106
|
-
expect(err).to.be.null;
|
|
1140
|
+
expect(err).to.be.null();
|
|
1107
1141
|
expect(value).to.deep.equal({ a: 1, b: 'a', d: 'c' });
|
|
1108
1142
|
done();
|
|
1109
1143
|
});
|
|
@@ -1126,12 +1160,12 @@ describe('Joi', function () {
|
|
|
1126
1160
|
|
|
1127
1161
|
localConfig.validate(obj, function (err, value) {
|
|
1128
1162
|
|
|
1129
|
-
expect(err).to.be.null;
|
|
1163
|
+
expect(err).to.be.null();
|
|
1130
1164
|
expect(value).to.deep.equal({ a: 1, b: 'a' });
|
|
1131
1165
|
|
|
1132
1166
|
localConfig.validate(value, function (err, value) {
|
|
1133
1167
|
|
|
1134
|
-
expect(err).to.be.null;
|
|
1168
|
+
expect(err).to.be.null();
|
|
1135
1169
|
expect(value).to.deep.equal({ a: 1, b: 'a' });
|
|
1136
1170
|
done();
|
|
1137
1171
|
});
|
|
@@ -1144,7 +1178,7 @@ describe('Joi', function () {
|
|
|
1144
1178
|
var input = { username: 'test', func: function () { } };
|
|
1145
1179
|
Joi.validate(input, schema, function (err, value) {
|
|
1146
1180
|
|
|
1147
|
-
expect(err).to.not.exist;
|
|
1181
|
+
expect(err).to.not.exist();
|
|
1148
1182
|
done();
|
|
1149
1183
|
});
|
|
1150
1184
|
});
|
|
@@ -1156,7 +1190,7 @@ describe('Joi', function () {
|
|
|
1156
1190
|
|
|
1157
1191
|
Joi.validate(input, schema, { skipFunctions: false }, function (err, value) {
|
|
1158
1192
|
|
|
1159
|
-
expect(err).to.exist;
|
|
1193
|
+
expect(err).to.exist();
|
|
1160
1194
|
expect(err.message).to.contain('func is not allowed');
|
|
1161
1195
|
done();
|
|
1162
1196
|
});
|
|
@@ -1171,7 +1205,7 @@ describe('Joi', function () {
|
|
|
1171
1205
|
var input = { arr: 'foo' };
|
|
1172
1206
|
Joi.validate(input, schema, { convert: false }, function (err, value) {
|
|
1173
1207
|
|
|
1174
|
-
expect(err).to.exist;
|
|
1208
|
+
expect(err).to.exist();
|
|
1175
1209
|
done();
|
|
1176
1210
|
});
|
|
1177
1211
|
});
|
|
@@ -1189,8 +1223,8 @@ describe('Joi', function () {
|
|
|
1189
1223
|
|
|
1190
1224
|
Joi.validate(input, schema, { abortEarly: false }, function (errFull, value) {
|
|
1191
1225
|
|
|
1192
|
-
expect(errOne).to.exist
|
|
1193
|
-
expect(errFull).to.exist
|
|
1226
|
+
expect(errOne).to.exist();
|
|
1227
|
+
expect(errFull).to.exist();
|
|
1194
1228
|
expect(errFull.details.length).to.be.greaterThan(errOne.details.length);
|
|
1195
1229
|
done();
|
|
1196
1230
|
});
|
|
@@ -1202,7 +1236,7 @@ describe('Joi', function () {
|
|
|
1202
1236
|
var any = Joi;
|
|
1203
1237
|
any.validate('abc', function (err, value) {
|
|
1204
1238
|
|
|
1205
|
-
expect(err).to.not.exist;
|
|
1239
|
+
expect(err).to.not.exist();
|
|
1206
1240
|
done();
|
|
1207
1241
|
});
|
|
1208
1242
|
});
|
|
@@ -1211,7 +1245,7 @@ describe('Joi', function () {
|
|
|
1211
1245
|
|
|
1212
1246
|
var any = Joi;
|
|
1213
1247
|
var result = any.validate('abc');
|
|
1214
|
-
expect(result.error).to.not.exist;
|
|
1248
|
+
expect(result.error).to.not.exist();
|
|
1215
1249
|
expect(result.value).to.equal('abc');
|
|
1216
1250
|
done();
|
|
1217
1251
|
});
|
|
@@ -1220,7 +1254,7 @@ describe('Joi', function () {
|
|
|
1220
1254
|
|
|
1221
1255
|
Joi.validate('test', Joi.string(), function (err, value) {
|
|
1222
1256
|
|
|
1223
|
-
expect(err).to.not.exist;
|
|
1257
|
+
expect(err).to.not.exist();
|
|
1224
1258
|
done();
|
|
1225
1259
|
});
|
|
1226
1260
|
});
|
|
@@ -1228,7 +1262,7 @@ describe('Joi', function () {
|
|
|
1228
1262
|
it('accepts no options (no callback)', function (done) {
|
|
1229
1263
|
|
|
1230
1264
|
var result = Joi.validate('test', Joi.string());
|
|
1231
|
-
expect(result.error).to.not.exist;
|
|
1265
|
+
expect(result.error).to.not.exist();
|
|
1232
1266
|
expect(result.value).to.equal('test');
|
|
1233
1267
|
done();
|
|
1234
1268
|
});
|
|
@@ -1237,7 +1271,7 @@ describe('Joi', function () {
|
|
|
1237
1271
|
|
|
1238
1272
|
Joi.validate('5', Joi.number(), { convert: false }, function (err, value) {
|
|
1239
1273
|
|
|
1240
|
-
expect(err).to.exist;
|
|
1274
|
+
expect(err).to.exist();
|
|
1241
1275
|
done();
|
|
1242
1276
|
});
|
|
1243
1277
|
});
|
|
@@ -1245,7 +1279,7 @@ describe('Joi', function () {
|
|
|
1245
1279
|
it('accepts options (no callback)', function (done) {
|
|
1246
1280
|
|
|
1247
1281
|
var result = Joi.validate('5', Joi.number(), { convert: false });
|
|
1248
|
-
expect(result.error).to.exist;
|
|
1282
|
+
expect(result.error).to.exist();
|
|
1249
1283
|
done();
|
|
1250
1284
|
});
|
|
1251
1285
|
|
|
@@ -1253,7 +1287,7 @@ describe('Joi', function () {
|
|
|
1253
1287
|
|
|
1254
1288
|
Joi.validate('test', Joi.string(), null, function (err, value) {
|
|
1255
1289
|
|
|
1256
|
-
expect(err).to.not.exist;
|
|
1290
|
+
expect(err).to.not.exist();
|
|
1257
1291
|
done();
|
|
1258
1292
|
});
|
|
1259
1293
|
});
|
|
@@ -1262,7 +1296,7 @@ describe('Joi', function () {
|
|
|
1262
1296
|
|
|
1263
1297
|
Joi.validate('test', Joi.string(), undefined, function (err, value) {
|
|
1264
1298
|
|
|
1265
|
-
expect(err).to.not.exist;
|
|
1299
|
+
expect(err).to.not.exist();
|
|
1266
1300
|
done();
|
|
1267
1301
|
});
|
|
1268
1302
|
});
|
|
@@ -1397,7 +1431,7 @@ describe('Joi', function () {
|
|
|
1397
1431
|
it('describes schema without invalids', function (done) {
|
|
1398
1432
|
|
|
1399
1433
|
var description = Joi.allow(null).describe();
|
|
1400
|
-
expect(description.invalids).to.not.exist;
|
|
1434
|
+
expect(description.invalids).to.not.exist();
|
|
1401
1435
|
done();
|
|
1402
1436
|
})
|
|
1403
1437
|
});
|
|
@@ -1421,5 +1455,14 @@ describe('Joi', function () {
|
|
|
1421
1455
|
}).to.not.throw();
|
|
1422
1456
|
done();
|
|
1423
1457
|
});
|
|
1458
|
+
|
|
1459
|
+
it('throws on invalid value with message', function (done) {
|
|
1460
|
+
|
|
1461
|
+
expect(function () {
|
|
1462
|
+
|
|
1463
|
+
Joi.assert('x', Joi.number(), 'the reason is');
|
|
1464
|
+
}).to.throw('the reason is "x"\n\u001b[31m\n[1] value must be a number\u001b[0m');
|
|
1465
|
+
done();
|
|
1466
|
+
});
|
|
1424
1467
|
});
|
|
1425
1468
|
});
|