UNPKG

1.13 kBJavaScriptView Raw
1'use strict';
2
3var Velocity = require('../src/velocity');
4var render = Velocity.render;
5
6describe('stop', function() {
7 it('should support #stop', function() {
8 var str = `hello #stop('hello') world`;
9 render(str).trim().should.eql('hello');
10 });
11
12 it('should support #stop in loop', function() {
13 var str = `
14 <ul>
15 #foreach( $product in $items )
16 #if ($product == 'world') #stop() #end
17 <li>$product</li>
18 #end
19 </ul>
20 `;
21 var ret = render(str, { items: ['hello', 'world']}).trim();
22 ret.should.containEql('<li>hello</li>');
23 ret.should.not.containEql('<li>world</li>');
24 });
25
26 it('should support #stop in #parse', function() {
27 var str = `
28 <p>hello</p>
29 #parse($a)
30 this should stop ouput
31 `;
32 var ret = render(str, {
33 a: `
34 this is a
35 #stop('stop a')
36 this is stop end
37 `
38 }, {
39 parse: function(template) {
40 return this.eval(template);
41 }
42 }).trim();
43 ret.should.containEql('<p>hello</p>');
44 ret.should.containEql('this is a');
45 ret.should.not.containEql('stop');
46 });
47});