-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
80 lines (71 loc) · 2.38 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
var vows = require('perjury'),
assert = vows.assert;
var suite = vows.describe('stratic-handle-offset module').addBatch({
'When we mock out Date#getTimezoneOffset': {
topic: function() {
Date.prototype.getTimezoneOffset = function getTimezoneOffset() {
return 0;
};
return Date;
},
'it works': function(err) {
assert.ifError(err);
},
'it behaves how we expect': function() {
assert.equal((new Date()).getTimezoneOffset(), 0);
},
'and we require the module': {
topic: function() {
return require('./index.js');
},
'it works': function(err) {
assert.ifError(err);
},
'and we pass it a time object': {
topic: function(handleOffset) {
return handleOffset({
/*
This time is taken from a real-word cause of the timezone
(well, offset) bug this module is designed to handle.
The post in question was written on 2016-08-26. However,
without proper offset support, in any timezone to the east
of where it was authored - Pacific Time - it's
parsed as having been authored 2016-08-27.
*/
epoch: 1472279874,
utcoffset: 'UTC-7'
});
},
'it works': function(err) {
assert.ifError(err);
},
'it returns a moment object': function(err, obj) {
assert.isTrue(require('moment').fn.isPrototypeOf(obj));
},
'the day is correct': function(err, moment) {
assert.strictEqual(moment.date(), 26);
},
'the month is correct': function(err, moment) {
// month() returns 0 for January
assert.strictEqual(moment.month(), 7);
},
'the year is correct': function(err, moment) {
assert.strictEqual(moment.year(), 2016);
}
}
}
}
}).export(module);