mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
chore(TypeScript): refactor objects into classes
fix: `Nil`(null, undefined) now renders as empty string change: `parser.parseValue()` renamed to `parser.parseOutput` change: registered tags/filters become static and shared across different liquid instances
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { read } from 'src/parser/template-browser'
|
||||
import * as sinon from 'sinon'
|
||||
import * as 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 as any).XMLHttpRequest = sinon.useFakeXMLHttpRequest()
|
||||
})
|
||||
afterEach(() => {
|
||||
server.restore()
|
||||
delete (global as any).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