diff options
Diffstat (limited to 'tests/eval.spec.ts')
| -rw-r--r-- | tests/eval.spec.ts | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/tests/eval.spec.ts b/tests/eval.spec.ts index 63062e3..8b7424f 100644 --- a/tests/eval.spec.ts +++ b/tests/eval.spec.ts @@ -1,10 +1,15 @@ -import { Dependencies, evalExpr } from '../src/eval' +import { EvalActions, evalExpr } from '../src/eval' import { Expr } from '../src/parser' describe('eval', () => { - const deps: Dependencies = { + const deps: EvalActions = { addClass: jest.fn(), removeClass: jest.fn(), + delay: jest.fn(), + jsEval: jest.fn(), + loadCssx: jest.fn(), + getVariable: jest.fn(), + updateVariable: jest.fn(), } it('should add classes', async () => { @@ -17,7 +22,7 @@ describe('eval', () => { expect(deps.addClass).toHaveBeenCalledWith('element-id', 'class-name') }) - it('should add classes', async () => { + it('should remove classes', async () => { await evalExpr(Expr.Call({ name: 'remove-class', args: [ Expr.Identifier('element-id'), Expr.LiteralString('class-name') ], @@ -26,4 +31,24 @@ describe('eval', () => { 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') + }) }) |
