aboutsummaryrefslogtreecommitdiff
path: root/tests/eval.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/eval.spec.ts67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/eval.spec.ts b/tests/eval.spec.ts
new file mode 100644
index 0000000..2212ba4
--- /dev/null
+++ b/tests/eval.spec.ts
@@ -0,0 +1,67 @@
+import { EvalActions, evalExpr } from '../src/eval'
+import { Expr } from '../src/parser'
+
+describe('eval', () => {
+ const deps: EvalActions = {
+ addClass: jest.fn(),
+ removeClass: jest.fn(),
+ delay: jest.fn(),
+ jsEval: jest.fn(),
+ loadCssx: jest.fn(),
+ getVariable: jest.fn(),
+ updateVariable: jest.fn(),
+ setAttribute: jest.fn(),
+ }
+
+ it('should add classes', async () => {
+ await evalExpr(
+ Expr.Call({
+ name: 'add-class',
+ args: [Expr.Identifier('element-id'), Expr.LiteralString('class-name')],
+ }),
+ deps,
+ )
+
+ expect(deps.addClass).toHaveBeenCalledTimes(1)
+ expect(deps.addClass).toHaveBeenCalledWith('element-id', 'class-name')
+ })
+
+ it('should remove classes', async () => {
+ await evalExpr(
+ Expr.Call({
+ name: 'remove-class',
+ args: [Expr.Identifier('element-id'), Expr.LiteralString('class-name')],
+ }),
+ deps,
+ )
+
+ expect(deps.removeClass).toHaveBeenCalledTimes(1)
+ expect(deps.removeClass).toHaveBeenCalledWith('element-id', 'class-name')
+ })
+
+ it('should add a delay', async () => {
+ await evalExpr(
+ Expr.Call({
+ name: 'delay',
+ args: [Expr.LiteralString('200')],
+ }),
+ deps,
+ )
+
+ expect(deps.delay).toHaveBeenCalledTimes(1)
+ expect(deps.delay).toHaveBeenCalledWith(200)
+ })
+
+ it('should get variable', async () => {
+ await evalExpr(
+ Expr.Call({
+ name: 'var',
+ args: [Expr.LiteralString('--my-var'), Expr.LiteralString('def value')],
+ }),
+ deps,
+ )
+
+ expect(deps.getVariable).toHaveBeenCalledTimes(1)
+ expect(deps.getVariable).toHaveBeenCalledWith('--my-var')
+ })
+})