This commit is contained in:
harttle
2019-01-28 18:06:47 +08:00
parent 7a2e036c79
commit 8a881ac69a
41 changed files with 116 additions and 116 deletions
+3 -3
View File
@@ -13,7 +13,7 @@ describe('.parseAndRender()', function () {
})
})
it('should value object', function () {
var ctx = { obj: {foo: 'bar'} }
var ctx = { obj: { foo: 'bar' } }
return expect(engine.parseAndRender('{{obj}}', ctx)).to.eventually.equal('{"foo":"bar"}')
})
it('should value array', function () {
@@ -39,7 +39,7 @@ describe('.parseAndRender()', function () {
}).to.not.throw()
})
it('should render template multiple times', function () {
var ctx = {obj: {foo: 'bar'}}
var ctx = { obj: { foo: 'bar' } }
var template = engine.parse('{{obj}}')
return engine.render(template, ctx)
.then(result => expect(result).to.equal('{"foo":"bar"}'))
@@ -47,7 +47,7 @@ describe('.parseAndRender()', function () {
.then((result) => expect(result).to.equal('{"foo":"bar"}'))
})
it('should render filters', function () {
var ctx = {names: ['alice', 'bob']}
var ctx = { names: ['alice', 'bob'] }
var template = engine.parse('<p>{{names | join: ","}}</p>')
return expect(engine.render(template, ctx)).to.eventually.equal('<p>alice,bob</p>')
})
+3 -3
View File
@@ -29,7 +29,7 @@ describe('#renderFile()', function () {
.to.eventually.equal('foo')
})
it('should find files without extname', function () {
var engine = Liquid({root: '/root'})
var engine = Liquid({ root: '/root' })
return expect(engine.renderFile('/root/files/bar', {}))
.to.eventually.equal('bar')
})
@@ -57,11 +57,11 @@ describe('#renderFile()', function () {
.to.eventually.equal('FOO')
})
it('should render file with context', function () {
return expect(engine.renderFile('/root/files/name.html', {name: 'harttle'}))
return expect(engine.renderFile('/root/files/name.html', { name: 'harttle' }))
.to.eventually.equal('My name is harttle.')
})
it('should use default extname', function () {
return expect(engine.renderFile('files/name', {name: 'harttle'})).to.eventually.equal('My name is harttle.')
return expect(engine.renderFile('files/name', { name: 'harttle' })).to.eventually.equal('My name is harttle.')
})
it('should throw with lookup list when file not exist', function () {
engine = Liquid({
+22 -22
View File
@@ -15,7 +15,7 @@ describe('xhr', () => {
server = sinon.createFakeServer()
server.autoRespond = true
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
var dom = new JSDOM('', {
url: 'https://example.com/foo/bar.html',
contentType: 'text/html',
@@ -35,29 +35,29 @@ describe('xhr', () => {
})
describe('#renderFile()', () => {
it('should support without extname', () => {
return expect(engine.renderFile('hello', {name: 'alice1'}))
return expect(engine.renderFile('hello', { name: 'alice1' }))
.to.eventually.equal('hello alice1')
})
it('should support with extname', () => {
return expect(engine.renderFile('hello.html', {name: 'alice2'}))
return expect(engine.renderFile('hello.html', { name: 'alice2' }))
.to.eventually.equal('hello alice2')
})
it('should support with absolute path', () => {
server.respondWith('GET', 'https://example.com/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo'])
[200, { 'Content-Type': 'text/plain' }, 'foo'])
return expect(engine.renderFile('/foo.html'))
.to.eventually.equal('foo')
})
it('should support with url', () => {
return expect(engine.renderFile('https://example.com/views/hello.html', {name: 'alice4'}))
return expect(engine.renderFile('https://example.com/views/hello.html', { name: 'alice4' }))
.to.eventually.equal('hello alice4')
})
it('should support include', () => {
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, {'Content-Type': 'text/plain'}, "hello {% include 'name.html' %}"])
[200, { 'Content-Type': 'text/plain' }, "hello {% include 'name.html' %}"])
server.respondWith('GET', 'https://example.com/views/name.html',
[200, {'Content-Type': 'text/plain'}, '{{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, '{{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should throw 404', () => {
@@ -82,8 +82,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://example.com/foo/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support empty root', () => {
@@ -92,8 +92,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('https://example.com/foo/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support with relative path', () => {
@@ -102,8 +102,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://example.com/foo/views/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support with absolute path', () => {
@@ -112,8 +112,8 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
it('should support with url', () => {
@@ -122,20 +122,20 @@ describe('xhr', () => {
extname: '.html'
})
server.respondWith('GET', 'https://foo.com/bar/hello.html',
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', {name: 'alice5'}))
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
return expect(engine.renderFile('hello.html', { name: 'alice5' }))
.to.eventually.equal('hello alice5')
})
})
describe('cache options', () => {
it('should be disabled by default', () => {
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo1'])
[200, { 'Content-Type': 'text/plain' }, 'foo1'])
return engine.renderFile('foo.html')
.then((html) => {
expect(html).to.equal('foo1')
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo2'])
[200, { 'Content-Type': 'text/plain' }, 'foo2'])
return engine.renderFile('foo.html')
})
.then(html => expect(html).to.equal('foo2'))
@@ -147,12 +147,12 @@ describe('xhr', () => {
cache: true
})
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo1'])
[200, { 'Content-Type': 'text/plain' }, 'foo1'])
return engine.renderFile('foo.html')
.then((html) => {
expect(html).to.equal('foo1')
server.respondWith('GET', 'https://example.com/views/foo.html',
[200, {'Content-Type': 'text/plain'}, 'foo2'])
[200, { 'Content-Type': 'text/plain' }, 'foo2'])
return engine.renderFile('foo.html')
})
.then(html => expect(html).to.equal('foo1'))