From c940e6c997d973aaf0f7473ecddb6a099e9f8c3b Mon Sep 17 00:00:00 2001 From: harttle Date: Sun, 12 May 2019 22:58:29 +0800 Subject: [PATCH] chore: try to make unit test locale independent --- test/integration/builtin/filters/date.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/integration/builtin/filters/date.ts b/test/integration/builtin/filters/date.ts index a7f7cdd8a..8353c9be8 100644 --- a/test/integration/builtin/filters/date.ts +++ b/test/integration/builtin/filters/date.ts @@ -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) })