mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 14:00:39 -07:00
test: cover all
This commit is contained in:
@@ -89,4 +89,8 @@ describe('filter', function () {
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal(['\'a\'', '"a"'])
|
||||
})
|
||||
|
||||
it('should not throw undefined filter by default', function () {
|
||||
expect(filter.construct('undefined').render('foo', scope)).to.equal('foo')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import Liquid from '../../src/index.js'
|
||||
import mock from 'mock-fs'
|
||||
import chai from 'chai'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Liquid', function () {
|
||||
describe('#constructor()', function () {
|
||||
it('should throw on illegal root', function () {
|
||||
expect(() => {
|
||||
new Liquid({root: {}}) // eslint-disable-line
|
||||
}).to.throw(/illegal root/)
|
||||
})
|
||||
})
|
||||
describe('#express()', function () {
|
||||
const liquid = new Liquid({root: '/root'})
|
||||
const render = liquid.express()
|
||||
before(function () {
|
||||
mock({
|
||||
'/root/foo': 'foo'
|
||||
})
|
||||
})
|
||||
after(function () {
|
||||
mock.restore()
|
||||
})
|
||||
it('should render single template', function (done) {
|
||||
render.call({root: '.'}, 'foo', null, (err, result) => {
|
||||
if (err) return done(err)
|
||||
expect(result).to.equal('foo')
|
||||
done()
|
||||
})
|
||||
})
|
||||
it('should render single template with Array-typed root', function (done) {
|
||||
render.call({root: ['.']}, 'foo', null, (err, result) => {
|
||||
if (err) return done(err)
|
||||
expect(result).to.equal('foo')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import {resolve} from '../../src/template.js'
|
||||
import mock from 'mock-fs'
|
||||
import chai from 'chai'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
|
||||
const expect = chai.expect
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
describe('template', function () {
|
||||
before(function () {
|
||||
mock({
|
||||
'/foo/bar.html': 'bar'
|
||||
})
|
||||
})
|
||||
describe('#resolve()', function () {
|
||||
it('should resolve based on root', function () {
|
||||
const filepath = resolve('bar.html', '/foo', {root: []})
|
||||
return expect(filepath).to.eventually.equal('/foo/bar.html')
|
||||
})
|
||||
it('should resolve based on root', function () {
|
||||
return expect(resolve('foo.html', '/foo', {root: []}))
|
||||
.to.rejectedWith(/Failed to lookup foo.html in: \/foo/)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import {read} from '../../src/template-browser.js'
|
||||
import sinon from 'sinon'
|
||||
import chai from 'chai'
|
||||
|
||||
chai.use(require('chai-as-promised'))
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('template-browser', () => {
|
||||
if (process.version.match(/^v(\d+)/)[1] < 8) {
|
||||
console.info('jsdom not supported, skipping xhr...')
|
||||
return
|
||||
}
|
||||
let server
|
||||
beforeEach(() => {
|
||||
server = sinon.createFakeServer()
|
||||
server.autoRespond = true
|
||||
server.respondWith('GET', 'https://example.com/views/hello.html',
|
||||
[200, {'Content-Type': 'text/plain'}, 'hello {{name}}'])
|
||||
global.XMLHttpRequest = sinon.useFakeXMLHttpRequest()
|
||||
})
|
||||
afterEach(() => {
|
||||
server.restore()
|
||||
delete global.XMLHttpRequest
|
||||
})
|
||||
describe('#read()', () => {
|
||||
it('should get corresponding text', () => {
|
||||
return expect(read('https://example.com/views/hello.html'))
|
||||
.to.eventually.equal('hello {{name}}')
|
||||
})
|
||||
it('should throw 404', () => {
|
||||
return expect(read('https://example.com/not/exist.html'))
|
||||
.to.be.rejectedWith('Not Found')
|
||||
})
|
||||
it('should throw error', function (done) {
|
||||
read('https://example.com/views/hello.html')
|
||||
.then(() => done('should not be resolved'))
|
||||
.catch(function (e) {
|
||||
expect(e.message).to.equal('An error occurred whilst receiving the response.')
|
||||
done()
|
||||
})
|
||||
server.requests[0].error()
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user