Files
liquidjs/test/unit/xhr.ts
T
harttle 677e8511e6 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
2019-02-17 04:55:30 +08:00

46 lines
1.4 KiB
TypeScript

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()
})
})
})