|
1 | | -import { Liquid } from '../../../src/liquid' |
| 1 | +import { Liquid, filters } from '../../../src' |
2 | 2 |
|
3 | 3 | describe('liquid#registerFilter()', function () { |
4 | 4 | let liquid: Liquid |
@@ -67,3 +67,32 @@ describe('liquid#registerFilter()', function () { |
67 | 67 | await expect(new Liquid({ strictFilters: true }).parseAndRender('{{ 1 | constructor }}')).rejects.toThrow('undefined filter') |
68 | 68 | }) |
69 | 69 | }) |
| 70 | + |
| 71 | +describe('liquid#unregisterFilter()', function () { |
| 72 | + let liquid: Liquid |
| 73 | + beforeEach(() => { liquid = new Liquid() }) |
| 74 | + |
| 75 | + it('should unregister a custom filter', async () => { |
| 76 | + liquid.registerFilter('greet', value => `hello ${value}`) |
| 77 | + liquid.unregisterFilter('greet') |
| 78 | + const html = await liquid.parseAndRender('{{ "world" | greet }}') |
| 79 | + return expect(html).toBe('world') |
| 80 | + }) |
| 81 | + |
| 82 | + it('should unregister a built-in filter', () => { |
| 83 | + liquid = new Liquid({ strictFilters: true }) |
| 84 | + liquid.unregisterFilter('upcase') |
| 85 | + return expect(liquid.parseAndRender('{{ "foo" | upcase }}')).rejects.toThrow('undefined filter: upcase') |
| 86 | + }) |
| 87 | + |
| 88 | + it('should support re-registering a built-in filter', async () => { |
| 89 | + liquid.unregisterFilter('upcase') |
| 90 | + liquid.registerFilter('upcase', filters.upcase) |
| 91 | + const html = await liquid.parseAndRender('{{ "foo" | upcase }}') |
| 92 | + return expect(html).toBe('FOO') |
| 93 | + }) |
| 94 | + |
| 95 | + it('should not throw for an unknown filter', () => { |
| 96 | + expect(() => liquid.unregisterFilter('unknown')).not.toThrow() |
| 97 | + }) |
| 98 | +}) |
0 commit comments