2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-07 15:20:26 +00:00
thumbsup/test/themes/helpers/date.spec.js
Romain 03a9c9a319 refactor: themes are now standalone folders, to prepare for external loading
Every theme is made of { Handlebars + Less + Partials + Helpers + Public }
2018-06-01 23:49:53 +02:00

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>`)
})
})