isvalid 3.2.3 → 3.2.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/test/validate.js +63 -61
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isvalid",
3
- "version": "3.2.3",
3
+ "version": "3.2.4",
4
4
  "description": "Async JSON validation library for node.js.",
5
5
  "main": "./index.js",
6
6
  "keywords": [
package/test/validate.js CHANGED
@@ -619,49 +619,49 @@ describe('validate', function() {
619
619
  .and.to.have.property('validator', 'unique');
620
620
  });
621
621
  });
622
- describe('autowrap', function() {
623
- it('should come back with non-array wrapped in array', () => {
624
- return expect(isvalid({
625
- test: true
626
- }, {
627
- type: Array,
628
- autowrap: true,
629
- schema: {
630
- test: Boolean
631
- }
632
- })).to.eventually.be.an('array').and.to.have.property(0).and.to.have.property('test', true);
633
- });
634
- it('should come back with type error if autowrap and not matching sub-schema.', () => {
635
- return expect(isvalid({
636
- test: 'Not a boolean'
637
- }, {
638
- type: Array,
639
- autowrap: true,
640
- schema: {
641
- test: Boolean
642
- }}))
643
- .to.eventually.be.rejectedWith('Is not of type boolean.')
644
- .and.to.be.instanceOf(ValidationError)
645
- .and.have.property('validator', 'type');
646
- });
647
- it('should come back with type error if no autowrap and matching sub-schema.', () => {
648
- return expect(isvalid({
649
- test: true
650
- }, [{
651
- test: Boolean}]))
652
- .to.eventually.be.rejectedWith('Is not of type array.')
653
- .and.to.be.instanceOf(ValidationError)
654
- .and.have.property('validator', 'type');
655
- });
656
- it('should prioritize concrete over defaults.', () => {
657
- return expect(isvalid(true, {
658
- type: Array,
659
- autowrap: false
660
- }, { defaults: { autowrap: true }}))
661
- .to.eventually.be.rejectedWith('Is not of type array.')
662
- .and.to.be.instanceOf(ValidationError)
663
- .and.have.property('validator', 'type');
664
- });
622
+ });
623
+ describe('autowrap', function() {
624
+ it('should come back with non-array wrapped in array', () => {
625
+ return expect(isvalid({
626
+ test: true
627
+ }, {
628
+ type: Array,
629
+ autowrap: true,
630
+ schema: {
631
+ test: Boolean
632
+ }
633
+ })).to.eventually.be.an('array').and.to.have.property(0).and.to.have.property('test', true);
634
+ });
635
+ it('should come back with type error if autowrap and not matching sub-schema.', () => {
636
+ return expect(isvalid({
637
+ test: 'Not a boolean'
638
+ }, {
639
+ type: Array,
640
+ autowrap: true,
641
+ schema: {
642
+ test: Boolean
643
+ }}))
644
+ .to.eventually.be.rejectedWith('Is not of type boolean.')
645
+ .and.to.be.instanceOf(ValidationError)
646
+ .and.have.property('validator', 'type');
647
+ });
648
+ it('should come back with type error if no autowrap and matching sub-schema.', () => {
649
+ return expect(isvalid({
650
+ test: true
651
+ }, [{
652
+ test: Boolean}]))
653
+ .to.eventually.be.rejectedWith('Is not of type array.')
654
+ .and.to.be.instanceOf(ValidationError)
655
+ .and.have.property('validator', 'type');
656
+ });
657
+ it('should prioritize concrete over defaults.', () => {
658
+ return expect(isvalid(true, {
659
+ type: Array,
660
+ autowrap: false
661
+ }, { defaults: { autowrap: true }}))
662
+ .to.eventually.be.rejectedWith('Is not of type array.')
663
+ .and.to.be.instanceOf(ValidationError)
664
+ .and.have.property('validator', 'type');
665
665
  });
666
666
  });
667
667
  });
@@ -771,24 +771,6 @@ describe('validate', function() {
771
771
  return expect(isvalid(123, Number))
772
772
  .to.eventually.equal(123);
773
773
  });
774
- it('should throw error if non-integers are not allowed.', () => {
775
- return expect(isvalid(2.2, { type: Number, float: 'deny' }))
776
- .to.eventually.be.rejectedWith('Number must be an integer.')
777
- .and.to.be.instanceOf(ValidationError)
778
- .and.have.property('validator', 'float');
779
- });
780
- it ('should come back with non-integer values if they are allowed.', () => {
781
- return expect(isvalid(2.2, { type: Number })).to.eventually.equal(2.2);
782
- });
783
- it ('should come back with number rounded if `float` is set to `round`.', () => {
784
- return expect(isvalid(2.5, { type: Number, float: 'round' })).to.eventually.equal(3);
785
- });
786
- it ('should come back with number ceiled if `float` is set to `ceil`.', () => {
787
- return expect(isvalid(2.2, { type: Number, float: 'ceil' })).to.eventually.equal(3);
788
- });
789
- it ('should come back with number floored if `float` is set to `floor`.', () => {
790
- return expect(isvalid(2.8, { type: Number, float: 'floor' })).to.eventually.equal(2);
791
- });
792
774
  describe('range', function() {
793
775
  it('should come back with error if input is not within range.', () => {
794
776
  return expect(isvalid(1, { type: Number, range: '2-4' }))
@@ -814,6 +796,26 @@ describe('validate', function() {
814
796
  });
815
797
  });
816
798
  });
799
+ describe('float', function() {
800
+ it('should throw error if non-integers are not allowed.', () => {
801
+ return expect(isvalid(2.2, { type: Number, float: 'deny' }))
802
+ .to.eventually.be.rejectedWith('Number must be an integer.')
803
+ .and.to.be.instanceOf(ValidationError)
804
+ .and.have.property('validator', 'float');
805
+ });
806
+ it ('should come back with non-integer values if they are allowed.', () => {
807
+ return expect(isvalid(2.2, { type: Number })).to.eventually.equal(2.2);
808
+ });
809
+ it ('should come back with number rounded if `float` is set to `round`.', () => {
810
+ return expect(isvalid(2.5, { type: Number, float: 'round' })).to.eventually.equal(3);
811
+ });
812
+ it ('should come back with number ceiled if `float` is set to `ceil`.', () => {
813
+ return expect(isvalid(2.2, { type: Number, float: 'ceil' })).to.eventually.equal(3);
814
+ });
815
+ it ('should come back with number floored if `float` is set to `floor`.', () => {
816
+ return expect(isvalid(2.8, { type: Number, float: 'floor' })).to.eventually.equal(2);
817
+ });
818
+ });
817
819
  });
818
820
  describe('date validator', function() {
819
821
  commonTests.all(Date, new Date(), 123);