-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
46 lines (37 loc) · 1.67 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
/*!
* helper-dateformat <https://github.com/jonschlinkert/helper-dateformat>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
*/
'use strict';
require('mocha');
var assert = require('assert');
var date = require('dateformat');
var handlebars = require('handlebars');
var _ = require('lodash');
var helper = require('./');
function dateformat(format) {
return date(new Date(), format);
}
describe('dateformat', function () {
it('should return a formatted date:', function () {
assert.deepEqual(helper(), dateformat('mmmm dd, yyyy'));
assert.deepEqual(helper(new Date()), dateformat('mmmm dd, yyyy'));
});
it('should return a formatted dateformat date:', function () {
assert.deepEqual(helper('mmmm dd, yyyy'), dateformat('mmmm dd, yyyy'));
assert.deepEqual(helper(new Date(), 'mmmm dd, yyyy'), dateformat('mmmm dd, yyyy'));
});
it('should work as a lodash helper:', function () {
assert.deepEqual(_.template('<%= date("mmmm dd, yyyy") %>', {}, {imports: {date: helper}}), dateformat('mmmm dd, yyyy'));
assert.deepEqual(_.template('<%= date("mmmm") %>', {}, {imports: {date: helper}}), dateformat('mmmm'));
assert.notDeepEqual(_.template('<%= date("mmmm dd, yyyy") %>', {}, {imports: {date: helper}}), dateformat('mmmm'));
});
it('should work as a handlebars helper:', function () {
handlebars.registerHelper('date', helper);
assert.deepEqual(handlebars.compile('{{date "mmmm dd, yyyy"}}')(), dateformat('mmmm dd, yyyy'));
assert.deepEqual(handlebars.compile('{{date "mmmm"}}')(), dateformat('mmmm'));
assert.notDeepEqual(handlebars.compile('{{date "mmmm"}}')(), dateformat('mmmm dd, yyyy'));
});
});