chore: migrate test cases from Chai to Jest

This commit is contained in:
Harttle
2023-03-20 00:41:06 +08:00
committed by Jun Yang
parent dccb90c591
commit c6cde9cd10
97 changed files with 8163 additions and 26440 deletions
+55
View File
@@ -0,0 +1,55 @@
import { Liquid } from '../..'
import { resolve } from 'path'
describe('#renderFile()', function () {
const root = resolve(__dirname, '../stub/root')
const views = resolve(__dirname, '../stub/views')
let engine: Liquid
beforeEach(function () {
engine = new Liquid({
root,
extname: '.html'
})
})
it('should render file', async function () {
const html = await engine.renderFile(resolve(root, 'foo.html'), {})
return expect(html).toBe('foo')
})
it('should find files without extname', async function () {
var engine = new Liquid({ root })
const html = await engine.renderFile(resolve(root, 'bar'), {})
return expect(html).toBe('bar')
})
it('should accept relative path', async function () {
const html = await engine.renderFile('foo.html')
return expect(html).toBe('foo')
})
it('should traverse root array', async function () {
engine = new Liquid({
root: ['/boo', root],
extname: '.html'
})
const html = await engine.renderFile('foo.html')
return expect(html).toBe('foo')
})
it('should default root to cwd', async function () {
engine = new Liquid()
const html = await engine.renderFile('package.json')
return expect(html).toContain('"name": "liquidjs"')
})
it('should render file with context', async function () {
const html = await engine.renderFile(resolve(views, 'name.html'), { name: 'harttle' })
return expect(html).toBe('My name is harttle.')
})
it('should use default extname', async function () {
const html = await engine.renderFile(resolve(root, 'foo'))
return expect(html).toBe('foo')
})
it('should throw with lookup list when file not exist', function () {
engine = new Liquid({
root: ['/boo', '/root/'],
extname: '.html'
})
return expect(engine.renderFile('/not/exist.html')).rejects.toThrow(/Failed to lookup "\/not\/exist.html" in "\/boo,\/root\/"/)
})
})