chore: try to make unit test locale independent

This commit is contained in:
harttle
2019-05-12 22:58:29 +08:00
parent d8ba009773
commit c940e6c997
+12 -8
View File
@@ -23,19 +23,23 @@ describe('filters/date', function () {
it('should render object as string if not valid', function () {
return test('{{ obj | date: "%Y"}}', '[object Object]')
})
it('should create from number-like string', async function () {
const src = '{{ "1488859200" | date: "%Y-%m-%dT%H:%M:%S" }}'
const dst = '2017-03-07T12:00:00'
expect(await liquid.parseAndRender(src)).to.equal(dst)
})
it('should create from number', async function () {
const src = '{{ 1488859200 | date: "%Y-%m-%dT%H:%M:%S" }}'
const time = new Date('2017-03-07T12:00:00').getTime() / 1000
const src = '{{ time | date: "%Y-%m-%dT%H:%M:%S" }}'
const ctx = { time }
const dst = '2017-03-07T12:00:00'
expect(await liquid.parseAndRender(src)).to.equal(dst)
expect(await liquid.parseAndRender(src, ctx)).to.equal(dst)
})
it('should create from number-like string', async function () {
const time = String(new Date('2017-03-07T12:00:00').getTime() / 1000)
const src = '{{ time | date: "%Y-%m-%dT%H:%M:%S" }}'
const ctx = { time }
const dst = '2017-03-07T12:00:00'
expect(await liquid.parseAndRender(src, ctx)).to.equal(dst)
})
it('should support manipulation', async function () {
const src = '{{ date | date: "%s" | minus : 604800 | date: "%Y-%m-%dT%H:%M:%S"}}'
const ctx = { date: new Date('2017-03-07 12:00:00.000+8:00') }
const ctx = { date: new Date('2017-03-07T12:00:00') }
const dst = '2017-02-28T12:00:00'
expect(await liquid.parseAndRender(src, ctx)).to.equal(dst)
})