From 78550c0d1c7037b17bdaa9413351b759b20772c0 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 13 Aug 2023 18:46:16 +0530 Subject: feat: adds conditionals --- tests/eval.spec.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests/eval.spec.ts') diff --git a/tests/eval.spec.ts b/tests/eval.spec.ts index 2212ba4..1d8b161 100644 --- a/tests/eval.spec.ts +++ b/tests/eval.spec.ts @@ -26,6 +26,50 @@ describe('eval', () => { expect(deps.addClass).toHaveBeenCalledWith('element-id', 'class-name') }) + it('should allow conditionals classes', async () => { + expect( + await evalExpr( + Expr.Call({ + name: 'if', + args: [ + Expr.Identifier('true'), + Expr.Identifier('yes'), + Expr.Identifier('no'), + ], + }), + deps, + ), + ).toBe('yes') + + expect( + await evalExpr( + Expr.Call({ + name: 'if', + args: [ + Expr.Identifier('false'), + Expr.Identifier('yes'), + Expr.Identifier('no'), + ], + }), + deps, + ), + ).toBe('no') + + expect( + await evalExpr( + Expr.Call({ + name: 'if', + args: [ + Expr.Identifier('0'), + Expr.Identifier('yes'), + Expr.Identifier('no'), + ], + }), + deps, + ), + ).toBe('no') + }) + it('should remove classes', async () => { await evalExpr( Expr.Call({ -- cgit v1.3.1