|
2 | 2 | var chai = require('chai') |
3 | 3 | , chaiAsPromised = require('chai-as-promised') |
4 | 4 | , Promise = require('promise/src/es6-extensions') |
5 | | - , date = require('../src/date'); |
| 5 | + , { ref, date } = require('../src'); |
6 | 6 |
|
7 | 7 | chai.use(chaiAsPromised); |
8 | 8 | chai.should(); |
@@ -56,28 +56,48 @@ describe('Date types', function(){ |
56 | 56 | }) |
57 | 57 |
|
58 | 58 | it('should check MIN correctly', function(){ |
59 | | - var v = date().min(new Date(2014, 3, 15)); |
| 59 | + var min = new Date(2014, 3, 15) |
| 60 | + , invalid = new Date(2014, 1, 15) |
| 61 | + , valid = new Date(2014, 5, 15) |
60 | 62 |
|
61 | 63 | ;(function(){ date().max('hello') }).should.throw(TypeError) |
| 64 | + ;(function(){ date().max(ref('$foo')) }).should.not.throw |
62 | 65 |
|
63 | 66 | return Promise.all([ |
64 | | - v.isValid(new Date(2014, 5, 15)).should.eventually.equal(true), |
65 | | - v.isValid(new Date(2014, 1, 15)).should.eventually.equal(false), |
66 | | - |
67 | | - v.isValid(null).should.eventually.equal(false) |
| 67 | + date().min(min).isValid(valid).should.eventually.equal(true), |
| 68 | + date().min(min).isValid(invalid).should.eventually.equal(false), |
| 69 | + date().min(min).isValid(null).should.eventually.equal(false), |
| 70 | + |
| 71 | + date().min(ref('$foo')) |
| 72 | + .isValid(valid, { context: { foo: min }}) |
| 73 | + .should.eventually.equal(true), |
| 74 | + date().min(ref('$foo')) |
| 75 | + .isValid(invalid, { context: { foo: min }}) |
| 76 | + .should.eventually.equal(false) |
68 | 77 | ]) |
69 | 78 | }) |
70 | 79 |
|
71 | | - it('should check MAX correctly', function(){ |
72 | | - var v = date().max(new Date(2014, 7, 15)); |
| 80 | + it('should check MAX correctly', function() { |
| 81 | + var max = new Date(2014, 7, 15) |
| 82 | + , invalid = new Date(2014, 9, 15) |
| 83 | + , valid = new Date(2014, 5, 15) |
73 | 84 |
|
74 | 85 | ;(function(){ date().max('hello') }).should.throw(TypeError) |
| 86 | + ;(function(){ date().max(ref('$foo')) }).should.not.throw |
75 | 87 |
|
76 | 88 | return Promise.all([ |
77 | | - v.isValid(new Date(2014, 5, 15)).should.eventually.equal(true), |
78 | | - v.isValid(new Date(2014, 9, 15)).should.eventually.equal(false), |
79 | | - v.nullable(true).isValid(null).should.eventually.equal(true) |
| 89 | + date().max(max).isValid(valid).should.eventually.equal(true), |
| 90 | + date().max(max).isValid(invalid).should.eventually.equal(false), |
| 91 | + date().max(max) |
| 92 | + .nullable(true) |
| 93 | + .isValid(null).should.eventually.equal(true), |
| 94 | + |
| 95 | + date().max(ref('$foo')) |
| 96 | + .isValid(valid, { context: { foo: max }}) |
| 97 | + .should.eventually.equal(true), |
| 98 | + date().max(ref('$foo')) |
| 99 | + .isValid(invalid, { context: { foo: max }}) |
| 100 | + .should.eventually.equal(false) |
80 | 101 | ]) |
81 | 102 | }) |
82 | 103 | }) |
83 | | - |
|
0 commit comments