mirror of
https://github.com/thumbsup/thumbsup
synced 2024-11-07 15:20:26 +00:00
03a9c9a319
Every theme is made of { Handlebars + Less + Partials + Helpers + Public }
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
const date = require('../../../themes/base/helpers/date')
|
|
const handlebars = require('handlebars')
|
|
const moment = require('moment')
|
|
const should = require('should/as-function')
|
|
|
|
describe('Handlebars helpers: date', () => {
|
|
handlebars.registerHelper('date', date)
|
|
|
|
it('renders a date as DD MMM YYYY by default', () => {
|
|
const template = handlebars.compile(`<p>{{date taken}}</p>`)
|
|
const res = template({taken: new Date(2017, 10, 27)}) // month is 0-based
|
|
should(res).eql('<p>27 Nov 2017</p>')
|
|
})
|
|
|
|
it('renders a date with a custom format', () => {
|
|
const template = handlebars.compile(`<p>{{date taken "MMMM YYYY"}}</p>`)
|
|
const res = template({taken: new Date(2017, 10, 27)}) // month is 0-based
|
|
should(res).eql('<p>November 2017</p>')
|
|
})
|
|
|
|
it('renders a date as <time ago>', () => {
|
|
const template = handlebars.compile(`<p>{{date taken "ago"}}</p>`)
|
|
const data = {taken: new Date(2017, 10, 27)} // month is 0-based
|
|
const res = template(data)
|
|
const expected = moment(data.taken).fromNow()
|
|
should(res).match(/<p>(.*) ago<\/p>/)
|
|
should(res).eql(`<p>${expected}</p>`)
|
|
})
|
|
})
|