-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcoffeescript.coffee
32 lines (27 loc) · 1.68 KB
/
coffeescript.coffee
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
expect = require 'expect.js'
{renderable, coffeescript} = require '..'
describe 'coffeescript', ->
it 'renders script tag and javascript with coffee preamble scoped only to that javascript', ->
template = renderable -> coffeescript -> alert 'hi'
expected = """<script type="text/javascript">(function() {
var __slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
(function () {
return alert(\'hi\');
})();
})();</script>"""
# Equal ignoring whitespace
expect(template().replace(/[\n ]/g, '')).to.equal expected.replace(/[\n ]/g, '')
it 'escapes the function contents for script tag', ->
template = renderable -> coffeescript ->
user = name: '</script><script>alert("alert");</script>'
alert "Hello #{user.name}!"
expect(template()).to.contain "'</script><script>alert("alert");</script>'"
# it 'string should render', ->
# t = -> coffeescript "alert 'hi'"
# assert.equal cc.render(t), "<script type=\"text/coffeescript\">alert 'hi'</script>"
# it 'object should render', ->
# t = -> coffeescript src: 'script.coffee'
# assert.equal cc.render(t), "<script src=\"script.coffee\" type=\"text/coffeescript\"></script>"