-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
82 lines (59 loc) · 1.84 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
81
82
var humanize = require('./lib/humanize')
var storage = require('./lib/storage')
var renderContent = require('./lib/renderContent')
describe('humanize', () => {
it('formats the date', done => {
if (
humanize.prettyDate('2017-03-28T13:42:09.3233868') !== '2017-03-28 13:42'
)
return done('format is incorrect')
done()
})
it('displays a timespan', done => {
if (humanize(new Date()) !== '0 seconds') return done('format is incorrect')
done()
})
it('displays a timespan for a day', done => {
if (humanize(addDays(-1)) !== '1 day') return done('format is incorrect')
done()
})
})
describe('storage', () => {
it('polyfills localstorage', done => {
if (storage.get('foo')) return done('expected null')
storage.put('foo', 'bar')
if ('bar' !== storage.get('foo')) return done('expected bar')
storage.del('foo')
if (storage.get('foo')) return done('expected value to be deleted')
done()
})
})
describe('memStorage', () => {
it('a local memory store', done => {
if (storage.get('foo')) return done('expected null')
storage.put('foo', 'bar')
if ('bar' !== storage.get('foo')) return done('expected bar')
storage.del('foo')
if (storage.get('foo')) return done('expected value to be deleted')
done()
})
})
describe('renderContent', () => {
it('renders markdown', done => {
var content = renderContent('# Hello World')
if ('<h1 id="hello-world">Hello World</h1>\n' !== content)
return done(`content not rendered correctly (${content})`)
done()
})
it('renders emoji', done => {
var content = renderContent(':sparkles:')
if ('<p>✨</p>\n' !== content)
return done(`content not rendered correctly (${content})`)
done()
})
})
function addDays(days) {
var date = new Date()
date.setDate(date.getDate() + days)
return date
}