refactor: strictly typed

This commit is contained in:
harttle
2019-02-23 00:49:54 +08:00
parent 51f7e66f60
commit 5b6100d12b
86 changed files with 2630 additions and 2590 deletions
+2 -2
View File
@@ -2,10 +2,10 @@ import { expect } from 'chai'
import Liquid from '../..'
describe('.evalValue()', function () {
var engine
var engine: Liquid
beforeEach(() => { engine = new Liquid() })
it('should throw when scope undefined', function () {
expect(() => engine.evalValue('{{"foo"}}')).to.throw(/scope undefined/)
expect(() => engine.evalValue('{{"foo"}}', null as any)).to.throw(/scope undefined/)
})
})
+2 -2
View File
@@ -8,7 +8,7 @@ describe('express()', function () {
const root = resolve(__dirname, '../stub/root')
const views = resolve(__dirname, '../stub/views')
const partials = resolve(__dirname, '../stub/partials')
let app, engine
let app: express.Application, engine: Liquid
beforeEach(function () {
app = express()
@@ -45,7 +45,7 @@ describe('express()', function () {
}
const file = '/not-exist.html'
const ctx = {}
engine.express().call(view, file, ctx, function (err) {
engine.express().call(view, file, ctx, function (err: any) {
try {
expect(err.code).to.equal('ENOENT')
expect(err.message).to.match(/Failed to lookup/)
+1 -1
View File
@@ -5,7 +5,7 @@ import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('.parseAndRender()', function () {
var engine, strictEngine
var engine: Liquid, strictEngine: Liquid
beforeEach(function () {
engine = new Liquid()
strictEngine = new Liquid({
+1 -1
View File
@@ -8,7 +8,7 @@ use(chaiAsPromised)
describe('#renderFile()', function () {
const root = resolve(__dirname, '../stub/root')
const views = resolve(__dirname, '../stub/views')
let engine
let engine: Liquid
beforeEach(function () {
engine = new Liquid({
root,
+6 -6
View File
@@ -1,5 +1,5 @@
import Liquid from '../../dist/liquid.js'
import { createFakeServer, useFakeXMLHttpRequest } from 'sinon'
import * as sinon from 'sinon'
import { expect, use } from 'chai'
import { JSDOM } from 'jsdom'
import * as chaiAsPromised from 'chai-as-promised'
@@ -7,13 +7,13 @@ import * as chaiAsPromised from 'chai-as-promised'
use(chaiAsPromised)
describe('xhr', () => {
if (+process.version.match(/^v(\d+)/)[1] < 8) {
if (+(process.version.match(/^v(\d+)/) as RegExpMatchArray)[1] < 8) {
console.info('jsdom not supported, skipping xhr...')
return
}
let server, engine
let server: sinon.SinonFakeServer, engine: Liquid
beforeEach(() => {
server = createFakeServer()
server = sinon.fakeServer.create()
server.autoRespond = true
server.respondWith('GET', 'https://example.com/views/hello.html',
[200, { 'Content-Type': 'text/plain' }, 'hello {{name}}'])
@@ -22,7 +22,7 @@ describe('xhr', () => {
contentType: 'text/html',
includeNodeLocations: true
});
(global as any).XMLHttpRequest = useFakeXMLHttpRequest();
(global as any).XMLHttpRequest = sinon.FakeXMLHttpRequest;
(global as any).document = dom.window.document
engine = new Liquid({
root: 'https://example.com/views/',
@@ -68,7 +68,7 @@ describe('xhr', () => {
it('should throw error', function () {
const result = expect(engine.renderFile('hello.html'))
.to.be.rejectedWith('An error occurred whilst receiving the response.');
(global as any).XMLHttpRequest.onCreate = function (request) {
(global as any).XMLHttpRequest.onCreate = function (request: sinon.SinonFakeXMLHttpRequest) {
setTimeout(() => request.error())
}
return result