forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.unit.js
81 lines (53 loc) · 2.49 KB
/
date.unit.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
81
if (typeof module !== 'undefined') {
var assert = require('assert');
var sinon = require('sinon');
var faker = require('../index');
}
describe("date.js", function () {
describe("past()", function () {
it("returns a date N years into the past", function () {
var date = faker.date.past(75);
assert.ok(date < new Date());
});
it("returns a past date when N = 0", function () {
var refDate = new Date();
var date = faker.date.past(0, refDate.toJSON());
assert.ok(date < refDate); // date should be before the date given
});
it("returns a date N years before the date given", function () {
var refDate = new Date(2120, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
var date = faker.date.past(75, refDate.toJSON());
assert.ok(date < refDate && date > new Date()); // date should be before date given but after the current time
});
});
describe("future()", function () {
it("returns a date N years into the future", function () {
var date = faker.date.future(75);
assert.ok(date > new Date());
});
it("returns a future date when N = 0", function () {
var refDate = new Date();
var date = faker.date.future(0, refDate.toJSON());
assert.ok(date > refDate); // date should be after the date given
});
it("returns a date N years after the date given", function () {
var refDate = new Date(1880, 11, 9, 10, 0, 0, 0); // set the date beyond the usual calculation (to make sure this is working correctly)
var date = faker.date.future(75, refDate.toJSON());
assert.ok(date > refDate && date < new Date()); // date should be after the date given, but before the current time
});
});
describe("recent()", function () {
it("returns a date N days from the recent past", function () {
var date = faker.date.recent(30);
assert.ok(date <= new Date());
});
});
describe("between()", function () {
it("returns a random date between the dates given", function () {
var from = new Date(1990, 5, 7, 9, 11, 0, 0);
var to = new Date(2000, 6, 8, 10, 12, 0, 0);
var date = faker.date.between(from, to);
assert.ok(date > from && date < to);
});
});
});