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
@@ -1,52 +1,51 @@
import { expect } from 'chai'
import { Liquid } from '../../../src/liquid'
describe('drop/blank-drop', function () {
let liquid: Liquid
before(() => (liquid = new Liquid()))
beforeEach(() => (liquid = new Liquid()))
it('render blank drop as blank string', async function () {
const html = await liquid.parseAndRender('{{blank}}')
expect(html).to.equal('')
expect(html).toBe('')
})
it('blank equals nil', async function () {
const src = '{%if blank == nil %}blank == nil{%else%}blank != nil{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('blank == nil')
expect(html).toBe('blank == nil')
})
it('false is blank', async function () {
const src = '{%if false == blank %}false == blank{%else%}false != blank{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false == blank')
expect(html).toBe('false == blank')
})
it('"" is blank', async function () {
const src = '{%if "" == blank %}"" == blank{%else%}"" != blank{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('"" == blank')
expect(html).toBe('"" == blank')
})
it('" " is blank', async function () {
const src = '{%if " " == blank %}" " == blank{%else%}" " != blank{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('" " == blank')
expect(html).toBe('" " == blank')
})
it('{} is blank', async function () {
const src = '{%if obj == blank %}{} == blank{%else%}{} != blank{% endif %}'
const html = await liquid.parseAndRender(src, { obj: {} })
expect(html).to.equal('{} == blank')
expect(html).toBe('{} == blank')
})
it('{foo: 1} is not blank', async function () {
const src = '{%if obj == blank %}{foo: 1} == blank{%else%}{foo: 1} != blank{% endif %}'
const html = await liquid.parseAndRender(src, { obj: { foo: 1 } })
expect(html).to.equal('{foo: 1} != blank')
expect(html).toBe('{foo: 1} != blank')
})
it('[] is blank', async function () {
const src = '{%if arr == blank %}[] == blank{%else%}[] != blank{% endif %}'
const html = await liquid.parseAndRender(src, { arr: [] })
expect(html).to.equal('[] == blank')
expect(html).toBe('[] == blank')
})
it('[1] is not blank', async function () {
const src = '{%if arr == blank %}[1] == blank{%else%}[1] != blank{% endif %}'
const html = await liquid.parseAndRender(src, { arr: [1] })
expect(html).to.equal('[1] != blank')
expect(html).toBe('[1] != blank')
})
})
@@ -1,9 +1,8 @@
import { expect } from 'chai'
import { Liquid, Drop } from '../../../src'
describe('drop/drop', function () {
let liquid: Liquid
before(() => (liquid = new Liquid()))
beforeEach(() => (liquid = new Liquid()))
class CustomDrop extends Drop {
private name = 'NAME'
@@ -27,39 +26,39 @@ describe('drop/drop', function () {
}
it('should call corresponding method when output', async function () {
const html = await liquid.parseAndRender(`{{obj.getName}}`, { obj: new CustomDrop() })
expect(html).to.equal('GET NAME')
expect(html).toBe('GET NAME')
})
it('should call corresponding method when expression evaluates', async function () {
const html = await liquid.parseAndRender(`{% if obj.getName == "GET NAME" %}true{% endif %}`, { obj: new CustomDrop() })
expect(html).to.equal('true')
expect(html).toBe('true')
})
it('should read corresponding property', async function () {
const html = await liquid.parseAndRender(`{{obj.name}}`, { obj: new CustomDrop() })
expect(html).to.equal('NAME')
expect(html).toBe('NAME')
})
it('should output empty string if not exist', async function () {
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new CustomDrop() })
expect(html).to.equal('')
expect(html).toBe('')
})
it('should respect liquidMethodMissing', async function () {
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new CustomDropWithMethodMissing() })
expect(html).to.equal('FOO')
expect(html).toBe('FOO')
})
it('should call corresponding promise method', async function () {
const html = await liquid.parseAndRender(`{{obj.getName}}`, { obj: new PromiseDrop() })
expect(html).to.equal('GET NAME')
expect(html).toBe('GET NAME')
})
it('should read corresponding promise property', async function () {
const html = await liquid.parseAndRender(`{{obj.name}}`, { obj: new PromiseDrop() })
expect(html).to.equal('NAME')
expect(html).toBe('NAME')
})
it('should resolve before calling filters', async function () {
const html = await liquid.parseAndRender(`{{obj.name | downcase}}`, { obj: new PromiseDrop() })
expect(html).to.equal('name')
expect(html).toBe('name')
})
it('should support promise returned by liquidMethodMissing', async function () {
const html = await liquid.parseAndRender(`{{obj.foo}}`, { obj: new PromiseDrop() })
expect(html).to.equal('FOO')
expect(html).toBe('FOO')
})
it('should respect valueOf', async () => {
class CustomDrop extends Drop {
@@ -70,7 +69,7 @@ describe('drop/drop', function () {
}
const tpl = '{{drop}}: {% for field in drop %}{{ field }};{% endfor %}'
const html = await liquid.parseAndRender(tpl, { drop: new CustomDrop() })
expect(html).to.equal('foobar: foo;bar;')
expect(html).toBe('foobar: foo;bar;')
})
it('should support valueOf in == expression', async () => {
class AddressDrop extends Drop {
@@ -82,6 +81,6 @@ describe('drop/drop', function () {
const customer = { default_address: new AddressDrop() }
const tpl = `{% if address == customer.default_address %}{{address}}{% endif %}`
const html = await liquid.parseAndRender(tpl, { address, customer })
expect(html).to.equal('test')
expect(html).toBe('test')
})
})
@@ -1,92 +1,91 @@
import { expect } from 'chai'
import { Liquid } from '../../../src/liquid'
describe('drop/empty-drop', function () {
let liquid: Liquid
before(() => (liquid = new Liquid()))
beforeEach(() => (liquid = new Liquid()))
it('render empty drop as empty string', async function () {
const html = await liquid.parseAndRender('{{empty}}')
expect(html).to.equal('')
expect(html).toBe('')
})
it('nil is not empty', async function () {
const src = '{%if nil == empty %}nil == empty{%else%}nil != empty{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('nil != empty')
expect(html).toBe('nil != empty')
})
it('false is not empty', async function () {
const src = '{%if false == empty %}false == empty{%else%}false != empty{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false != empty')
expect(html).toBe('false != empty')
})
it('"" is empty', async function () {
const src = '{%if "" == empty %}"" == empty{%else%}"" != empty{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('"" == empty')
expect(html).toBe('"" == empty')
})
it('" " is not empty', async function () {
const src = '{%if " " == empty %}" " == empty{%else%}" " != empty{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('" " != empty')
expect(html).toBe('" " != empty')
})
it('{} is empty', async function () {
const src = '{%if obj == empty %}{} == empty{%else%}{} != empty{% endif %}'
const html = await liquid.parseAndRender(src, { obj: {} })
expect(html).to.equal('{} == empty')
expect(html).toBe('{} == empty')
})
it('{foo: 1} is not empty', async function () {
const src = '{%if obj == empty %}{foo: 1} == empty{%else%}{foo: 1} != empty{% endif %}'
const html = await liquid.parseAndRender(src, { obj: { foo: 1 } })
expect(html).to.equal('{foo: 1} != empty')
expect(html).toBe('{foo: 1} != empty')
})
it('[] is empty', async function () {
const src = '{%if arr == empty %}[] == empty{%else%}[] != empty{% endif %}'
const html = await liquid.parseAndRender(src, { arr: [] })
expect(html).to.equal('[] == empty')
expect(html).toBe('[] == empty')
})
it('[1] is not empty', async function () {
const src = '{%if arr == empty %}[1] == empty{%else%}[1] != empty{% endif %}'
const html = await liquid.parseAndRender(src, { arr: [1] })
expect(html).to.equal('[1] != empty')
expect(html).toBe('[1] != empty')
})
it('1 < empty should be false', async function () {
const src = '{%if 1 < empty %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false')
expect(html).toBe('false')
})
it('1 <= empty should be false', async function () {
const src = '{%if 1 <= empty %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false')
expect(html).toBe('false')
})
it('1 > empty should be false', async function () {
const src = '{%if 1 > empty %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false')
expect(html).toBe('false')
})
it('1 >= empty should be false', async function () {
const src = '{%if 1 >= empty %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false')
expect(html).toBe('false')
})
it('1 == empty should be false', async function () {
const src = '{%if 1 == empty %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false')
expect(html).toBe('false')
})
it('1 != empty should be true', async function () {
const src = '{%if 1 != empty %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('true')
expect(html).toBe('true')
})
it('empty != empty', async function () {
const src = '{%if empty == empty %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false')
expect(html).toBe('false')
})
it('empty != nil', async function () {
const src = '{%if empty == nil %}true{%else%}false{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('false')
expect(html).toBe('false')
})
})
@@ -1,41 +1,40 @@
import { expect } from 'chai'
import { Liquid } from '../../../src/liquid'
describe('drop/null-drop', function () {
let liquid: Liquid
before(() => (liquid = new Liquid()))
beforeEach(() => (liquid = new Liquid()))
it('render nil as empty string', async function () {
const html = await liquid.parseAndRender('{{nil}}')
expect(html).to.equal('')
expect(html).toBe('')
})
it('render null as empty string', async function () {
const html = await liquid.parseAndRender('{{null}}')
expect(html).to.equal('')
expect(html).toBe('')
})
it('undefined == null', async function () {
const src = '{%if foo == nil %}foo == nil{%else%}foo != nil{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('foo == nil')
expect(html).toBe('foo == nil')
})
it('nil != blank', async function () {
const src = '{%if nil == blank %}eq{%else%}neq{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('neq')
expect(html).toBe('neq')
})
it('nil != empty', async function () {
const src = '{%if nil == empty %}eq{%else%}neq{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('neq')
expect(html).toBe('neq')
})
it('0 != null', async function () {
const src = '{%if 0 == null %}0 == null{%else%}0 != null{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('0 != null')
expect(html).toBe('0 != null')
})
it('nil == null', async function () {
const src = '{%if nil == null %}nil == null{%else%}nil != null{% endif %}'
const html = await liquid.parseAndRender(src)
expect(html).to.equal('nil == null')
expect(html).toBe('nil == null')
})
})