mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
const chai = require("chai");
|
|
const expect = chai.expect;
|
|
const should = chai.should;
|
|
const Liquid = require('..');
|
|
|
|
describe('liquid', function() {
|
|
var engine, ctx;
|
|
beforeEach(function() {
|
|
engine = Liquid();
|
|
ctx = {
|
|
date: new Date(),
|
|
foo: 'bar',
|
|
arr: [-2, 'a'],
|
|
obj: {
|
|
foo: 'bar'
|
|
},
|
|
posts: [{
|
|
category: 'foo'
|
|
}, {
|
|
category: 'bar'
|
|
}]
|
|
};
|
|
});
|
|
it('should output object', function() {
|
|
engine.parseAndRender('{{obj}}', ctx).should.equal('{"foo":"bar"}');
|
|
});
|
|
it('should output array', function() {
|
|
engine.parseAndRender('{{arr}}', ctx).should.equal('[-2,"a"]');
|
|
});
|
|
it('should parse html', function() {
|
|
(function(){
|
|
engine.parse('{{obj}}');
|
|
}).should.not.throw();
|
|
(function(){
|
|
engine.parse('<html><head>{{obj}}</head></html>');
|
|
}).should.not.throw();
|
|
});
|
|
it('should render template multiple times', function() {
|
|
var template = engine.parse('{{obj}}');
|
|
engine.render(template, ctx).should.equal('{"foo":"bar"}');
|
|
engine.render(template, ctx).should.equal('{"foo":"bar"}');
|
|
});
|
|
it('should render filters', function() {
|
|
var template = engine.parse('<p>{{arr | join: "_"}}</p>');
|
|
engine.render(template, ctx).should.equal('<p>-2_a</p>');
|
|
});
|
|
});
|