File: runtime.js

package info (click to toggle)
node-handlebars 3%3A4.7.9-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,404 kB
  • sloc: javascript: 22,475; yacc: 136; lex: 125; sh: 72; ruby: 10; makefile: 7
file content (128 lines) | stat: -rw-r--r-- 3,548 bytes parent folder | download | duplicates (4)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
describe('runtime', function() {
  describe('#template', function() {
    it('should throw on invalid templates', function() {
      shouldThrow(
        function() {
          Handlebars.template({});
        },
        Error,
        'Unknown template object: object'
      );
      shouldThrow(
        function() {
          Handlebars.template();
        },
        Error,
        'Unknown template object: undefined'
      );
      shouldThrow(
        function() {
          Handlebars.template('');
        },
        Error,
        'Unknown template object: string'
      );
    });
    it('should throw on version mismatch', function() {
      shouldThrow(
        function() {
          Handlebars.template({
            main: {},
            compiler: [Handlebars.COMPILER_REVISION + 1]
          });
        },
        Error,
        /Template was precompiled with a newer version of Handlebars than the current runtime/
      );
      shouldThrow(
        function() {
          Handlebars.template({
            main: {},
            compiler: [Handlebars.LAST_COMPATIBLE_COMPILER_REVISION - 1]
          });
        },
        Error,
        /Template was precompiled with an older version of Handlebars than the current runtime/
      );
      shouldThrow(
        function() {
          Handlebars.template({
            main: {}
          });
        },
        Error,
        /Template was precompiled with an older version of Handlebars than the current runtime/
      );
    });

    it('should safely resolve missing partial map entries', function() {
      equal(
        Handlebars.VM.resolvePartial(undefined, {}, { name: 'missing' }),
        undefined
      );
    });
  });

  describe('#child', function() {
    if (!Handlebars.compile) {
      return;
    }

    it('should throw for depthed methods without depths', function() {
      shouldThrow(
        function() {
          var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
          // Calling twice to hit the non-compiled case.
          template._setup({});
          template._setup({});
          template._child(1);
        },
        Error,
        'must pass parent depths'
      );
    });

    it('should throw for block param methods without params', function() {
      shouldThrow(
        function() {
          var template = Handlebars.compile('{{#foo as |foo|}}{{foo}}{{/foo}}');
          // Calling twice to hit the non-compiled case.
          template._setup({});
          template._setup({});
          template._child(1);
        },
        Error,
        'must pass block params'
      );
    });
    it('should expose child template', function() {
      var template = Handlebars.compile('{{#foo}}bar{{/foo}}');
      // Calling twice to hit the non-compiled case.
      equal(template._child(0)(), 'bar');
      equal(template._child(0)(), 'bar');
    });
    it('should render depthed content', function() {
      var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
      // Calling twice to hit the non-compiled case.
      equal(template._child(0, undefined, [], [{ bar: 'baz' }])(), 'baz');
    });
  });

  describe('#noConflict', function() {
    if (!CompilerContext.browser) {
      return;
    }

    it('should reset on no conflict', function() {
      var reset = Handlebars;
      Handlebars.noConflict();
      equal(Handlebars, 'no-conflict');

      Handlebars = 'really, none';
      reset.noConflict();
      equal(Handlebars, 'really, none');

      Handlebars = reset;
    });
  });
});