Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

liquid.js 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  1. const { liquid } = require('../../lib/render-content')
  2. const template = `
  3. {% if page.version ver_gt "2.13" %}up to date{% endif %}
  4. {% if page.version ver_lt "2.13" %}out of date{% endif %}
  5. `
  6. describe('liquid template parser', () => {
  7. describe('custom operators', () => {
  8. describe('ver_gt', () => {
  9. test('works as expected', async () => {
  10. const context = {
  11. page: {
  12. version: '2.14'
  13. }
  14. }
  15. const output = await liquid.parseAndRender(template, context)
  16. expect(output.trim()).toBe('up to date')
  17. })
  18. test('returns false when given value is not numeric, like `dotcom`', async () => {
  19. const context = {
  20. page: {
  21. version: 'dotcom'
  22. }
  23. }
  24. const output = await liquid.parseAndRender(template, context)
  25. expect(output.trim()).toBe('')
  26. })
  27. test('returns false when given value is falsy', async () => {
  28. const context = {}
  29. const output = await liquid.parseAndRender(template, context)
  30. expect(output.trim()).toBe('')
  31. })
  32. })
  33. describe('ver_lt', () => {
  34. test('works as expected', async () => {
  35. const context = {
  36. page: {
  37. version: '2.12'
  38. }
  39. }
  40. const output = await liquid.parseAndRender(template, context)
  41. expect(output.trim()).toBe('out of date')
  42. })
  43. })
  44. })
  45. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...