'use strict'; require('mocha'); var assert = require('assert'); var hbs = require('handlebars').create(); var helpers = require('..'); helpers.html({handlebars: hbs}); var locals = {data: [{aaa: 'AAA', bbb: 'BBB'}, {aaa: 'CCC', bbb: 'DDD'}]}; var actual; describe('html', function() { describe('attr', function() { it('should strip html from a string.', function() { var actual = hbs.compile('
')({foo: 'btn'}); assert.equal(actual, ''); assert.equal(hbs.compile('{{attr}}')(), ''); }); }); describe('css', function() { it('should return an empty string when no context is passed:', function() { assert.equal(hbs.compile('{{{css}}}')(), ''); }); it('should use a path passed as a string', function() { var actual = hbs.compile('{{{css "abc.css"}}}')(); assert.equal(actual, ''); }); it('should use options.assets', function() { var actual = hbs.compile('{{{css "abc.css"}}}')({options: {assets: 'foo'}}); assert.equal(actual, ''); }); it('should ensure that options.assets is a string', function() { var actual = hbs.compile('{{{css "abc.css"}}}')({options: {assets: null}}); assert.equal(actual, ''); }); it('should not use options.assets when passing in an absolute url', function() { var actual = hbs.compile('{{{css "https://abc.com/bar.css"}}}')({options: {assets: 'foo'}}); assert.equal(actual, ''); }); it('should use the `href` attribute on the hash', function() { actual = hbs.compile('{{{css href=""}}}')(); assert.equal(actual, ''); actual = hbs.compile('{{{css href="abc.css"}}}')(); assert.equal(actual, ''); }); it('should create multiple tags from an array passed on the context:', function() { var ctx = {styles: ['a.css', 'bcss', 'c.css'] }; assert.equal(hbs.compile('{{{css styles}}}')(ctx), [ '', '', '' ].join('\n')); }); it('should create a less tag (TODO: only works with array format)', function() { var ctx = {styles: ['a.less'] }; assert.equal(hbs.compile('{{{css styles}}}')(ctx), ''); }); }); describe('js', function() { it('should create an empty script tag', function() { assert.equal(hbs.compile('{{{js}}}')(), ''); }); it('should use a path passed as a string', function() { assert.equal(hbs.compile('{{{js "abc.js"}}}')(), ''); }); it('should use the `src` attribute on the hash', function() { assert.equal(hbs.compile('{{{js src=""}}}')(), ''); assert.equal(hbs.compile('{{{js src="abc.js"}}}')(), ''); }); it('should create multiple tags from an array passed on the context:', function() { var ctx = {scripts: ['a.js', 'bjs', 'c.js'] }; assert.equal(hbs.compile('{{{js scripts}}}')(ctx), [ '', '', '' ].join('\n')); }); it('should create a coffeescript tag (TODO: only works with array format)', function() { var ctx = {scripts: ['a.coffee'] }; assert.equal(hbs.compile('{{{js scripts}}}')(ctx), ''); }); }); describe('sanitize', function() { it('should return an empty string when undefined.', function() { assert.equal(hbs.compile('{{sanitize}}')(), ''); }); it('should strip html from a string.', function() { var actual = hbs.compile('{{sanitize "foo"}}')(); assert.equal(actual, 'foo'); }); }); describe('ul', function() { it('should should return an unordered list', function() { var fn = hbs.compile('{{#ul data class="names"}}{{aaa}} {{bbb}}{{/ul}}'); assert.equal(fn(locals), '
',
'',
'
',
'',
'
',
'',
'
',
'',
'
',
'
',
'',
'