-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
52 lines (44 loc) · 1.39 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
var expect = require('chai').expect;
var Plugin = require('./');
describe('Plugin', () => {
var plugin;
beforeEach(() => {
plugin = new Plugin({});
});
it('should be an object', () => {
expect(plugin).to.be.ok;
});
it('should have a #compile method', () => {
expect(plugin.compile).to.be.an.instanceof(Function);
});
it('should compile and produce valid result', function(done) {
var content = '<p><%= "hello, world!".toUpperCase() %> <%= locals.var %></p>';
var expected = '<p>HELLO, WORLD! foo</p>';
plugin.compile({data: content}).then(module => {
try {
var tpl = eval(module);
expect(tpl({var: 'foo'})).to.equal(expected);
done();
} catch(err) {
done(err);
}
}, error => expect(error).not.to.be.ok);
});
it('should define an include function', function(done) {
var require = function(path) {
expect(path).to.equal("views/item");
return function(data) { return "<span>" + data.bar + "</span>" };
};
var content = '<p><%- include("item", { bar: 1 }) %></p>';
var expected = '<p><span>1</span></p>';
plugin.compile({path: 'app/views/index', data: content}).then(module => {
try {
var tpl = eval(module);
expect(tpl()).to.equal(expected);
done();
} catch(err) {
done(err);
}
}, error => expect(error).not.to.be.ok);
});
});