1 | (function() {
|
2 | var expect, util;
|
3 |
|
4 | if(typeof require != 'undefined') {
|
5 | expect = require('expect.js');
|
6 | util = require('./util');
|
7 | }
|
8 | else {
|
9 | expect = window.expect;
|
10 | util = window.util;
|
11 | }
|
12 |
|
13 | var equal = util.equal;
|
14 | var finish = util.finish;
|
15 | var render = util.render;
|
16 |
|
17 | describe('runtime', function() {
|
18 | it('should report the failed function calls to symbols', function(done) {
|
19 | render('{{ foo("cvan") }}', {}, { noThrow: true }, function(err) {
|
20 | expect(err).to.match(/Unable to call `foo`, which is undefined/);
|
21 | });
|
22 |
|
23 | finish(done);
|
24 | });
|
25 |
|
26 | it('should report the failed function calls to lookups', function(done) {
|
27 | render('{{ foo["bar"]("cvan") }}', {}, { noThrow: true }, function(err) {
|
28 | expect(err).to.match(/foo\["bar"\]/);
|
29 | });
|
30 |
|
31 | finish(done);
|
32 | });
|
33 |
|
34 | it('should report the failed function calls to calls', function(done) {
|
35 | render('{{ foo.bar("second call") }}', {}, { noThrow: true }, function(err) {
|
36 | expect(err).to.match(/foo\["bar"\]/);
|
37 | });
|
38 |
|
39 | finish(done);
|
40 | });
|
41 |
|
42 | it('should report the failed function calls w/multiple args', function(done) {
|
43 | render('{{ foo.bar("multiple", "args") }}', {}, { noThrow: true }, function(err) {
|
44 | expect(err).to.match(/foo\["bar"\]/);
|
45 | });
|
46 |
|
47 | render('{{ foo["bar"]["zip"]("multiple", "args") }}',
|
48 | {},
|
49 | { noThrow: true },
|
50 | function(err) {
|
51 | expect(err).to.match(/foo\["bar"\]\["zip"\]/);
|
52 | });
|
53 |
|
54 | finish(done);
|
55 | });
|
56 |
|
57 | it('should allow for undefined macro arguments in the last position', function(done) {
|
58 | render('{% macro foo(bar, baz) %}' +
|
59 | '{{ bar }} {{ baz }}{% endmacro %}' +
|
60 | '{{ foo("hello", none) }}',
|
61 | {},
|
62 | { noThrow: true },
|
63 | function(err, res) {
|
64 | expect(err).to.equal(null);
|
65 | expect(typeof res).to.be('string');
|
66 | });
|
67 |
|
68 | finish(done);
|
69 | });
|
70 | });
|
71 | })();
|