This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
28 lines (22 loc) · 2.18 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
global.expect = require('chai').expect;
global.Plugin = require('./');
describe('Plugin', function() {
var plugin;
beforeEach(function() {
plugin = new Plugin({});
});
it('should be an object', function() {
expect(plugin).to.be.ok;
});
it('should has #compile method', function() {
expect(plugin.compile).to.be.an.instanceof(Function);
});
it('should compile and produce valid result', function(done) {
var content = '<strong></strong>';
var expected = "var __templateData = function (__obj) {\n if (!__obj) __obj = {};\n var __out = [], __capture = function(callback) {\n var out = __out, result;\n __out = [];\n callback.call(this);\n result = __out.join('');\n __out = out;\n return __safe(result);\n }, __sanitize = function(value) {\n if (value && value.ecoSafe) {\n return value;\n } else if (typeof value !== 'undefined' && value != null) {\n return __escape(value);\n } else {\n return '';\n }\n }, __safe, __objSafe = __obj.safe, __escape = __obj.escape;\n __safe = __obj.safe = function(value) {\n if (value && value.ecoSafe) {\n return value;\n } else {\n if (!(typeof value !== 'undefined' && value != null)) value = '';\n var result = new String(value);\n result.ecoSafe = true;\n return result;\n }\n };\n if (!__escape) {\n __escape = __obj.escape = function(value) {\n return ('' + value)\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"');\n };\n }\n (function() {\n (function() {\n __out.push('<strong></strong>');\n \n }).call(this);\n \n }).call(__obj);\n __obj.safe = __objSafe, __obj.escape = __escape;\n return __out.join('');\n};\nif (typeof define === 'function' && define.amd) {\n define([], function() {\n return __templateData;\n });\n} else if (typeof module === 'object' && module && module.exports) {\n module.exports = __templateData;\n} else {\n __templateData;\n}";
plugin.compile({data: content, path: 'template.eco'}).then(data => {
expect(data).to.equal(expected)
done();
}, error => expect(error).not.to.be.ok);
});
});