-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
89 lines (75 loc) · 2.42 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
83
84
85
86
87
88
'use strict';
require('mocha');
var assert = require('assert');
var handlebars = require('handlebars');
var isObject = require('isobject');
var helpers = require('./');
var error = console.error;
var log = console.log;
function render(str, ctx) {
var hbs = handlebars.create();
hbs.registerHelper(helpers);
return hbs.compile(str)(ctx);
}
describe('logging helpers', function() {
beforeEach(function() {
error.history = [];
log.history = [];
console.log = function() {
var args = helpers.createArgs([].slice.call(arguments));
log.apply(console, args);
log.history.push.apply(log.history, args);
};
console.error = function() {
var args = helpers.createArgs([].slice.call(arguments));
error.history.push.apply(error.history, args);
error.apply(console, args);
};
});
afterEach(function() {
console.error = error;
console.log = log;
});
describe('{{log}}', function() {
it('should log a message to stdout', function() {
render('{{log "Log helper worked!"}}');
assert(/Log helper worked!/.test(log.history.join('')));
});
});
describe('{{warn}}', function() {
it('should log a warning message to stdout', function() {
render('{{warn "warn helper worked!"}}');
assert(/warn helper worked!/.test(error.history.join('')));
});
});
describe('{{success}}', function() {
it('should log a success message to stdout', function() {
render('{{success "success helper worked!"}}');
assert(/success helper worked!/.test(log.history.join('')));
});
});
describe('{{ok}}', function() {
it('should log an "ok" message to stdout', function() {
render('{{ok "ok helper worked!"}}');
assert(/ok helper worked!/.test(log.history.join('')));
});
});
describe('{{info}}', function() {
it('should log an info message to stdout', function() {
render('{{info "info helper worked!"}}');
assert(/info helper worked!/.test(log.history.join('')));
});
});
describe('{{error}}', function() {
it('should log an error message to stdout', function() {
render('{{error "error helper worked!"}}');
assert(/error helper worked!/.test(error.history.join('')));
});
});
describe('{{_debug}}', function() {
it('should log current context to stderr', function() {
render('{{_debug this}}', 'foo');
assert(/foo/.test(error.history.join('')));
});
});
});