1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/tests/unit/liquid-helpers.js
Peter Bengtsson 988e68fa98 JIT data (#32140)
2022-11-17 13:08:49 +00:00

64 lines
2.0 KiB
JavaScript

import { afterAll, jest, beforeAll, expect } from '@jest/globals'
import { liquid } from '../../lib/render-content/index.js'
import languages from '../../lib/languages.js'
import { DataDirectory } from '../helpers/data-directory.js'
describe('liquid helper tags', () => {
jest.setTimeout(60 * 1000)
const context = {}
let dd
const enDirBefore = languages.en.dir
beforeAll(() => {
context.currentLanguage = 'en'
dd = new DataDirectory({
data: {
reusables: {
example: 'a rose by any other name\nwould smell as sweet',
},
},
})
languages.en.dir = dd.root
})
afterAll(() => {
dd.destroy()
languages.en.dir = enDirBefore
})
describe('indented_data_reference tag', () => {
test('without any number of spaces specified', async () => {
const template = '{% indented_data_reference reusables.example %}'
const expected = ` a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})
test('with 0 spaces specified', async () => {
const template = '{% indented_data_reference reusables.example spaces=0 %}'
const expected = `a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})
test('with 0 spaces specified and whitespace around equals sign', async () => {
const template = '{% indented_data_reference reusables.example spaces = 0 %}'
const expected = `a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})
test('with 5 spaces specified', async () => {
const template = '{% indented_data_reference reusables.example spaces=5 %}'
const expected = ` a rose by any other name
would smell as sweet`
const output = await liquid.parseAndRender(template, context)
expect(output).toBe(expected)
})
})
})