From 874edcd5b27a7ed3572604a00ae7b608a6cb78b1 Mon Sep 17 00:00:00 2001 From: Alexander Sennikov Date: Wed, 24 Aug 2022 13:11:54 +0400 Subject: [PATCH] provide a failing use case for arguments mutation by evaluate function --- test/implementation-tests.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/implementation-tests.js b/test/implementation-tests.js index 9c58a0dc..816c378e 100644 --- a/test/implementation-tests.js +++ b/test/implementation-tests.js @@ -557,8 +557,36 @@ describe("Tests that bind Javascript functions", () => { var result = expr.evaluate(); var expected = [true, false]; expect(result).to.deep.equal(expected); - }) + }); + }); +}); +describe("Tests that bind variables", () => { + describe("Provide variable to JSONata evaluation", function() { + it("should return bound variable number", function() { + var expr = jsonata("$myVariable"); + var myVariable = { "foo": "bar" }; + var result = expr.evaluate(testdata2, { myVariable }); + expect(result).to.deep.equal({ "foo": "bar" }); + }); + + it("should not mutate bound variable on success", function() { + var expr = jsonata("$myVariable"); + var myVariable = { "foo": "bar" }; + expr.evaluate(testdata2, { myVariable }); + expect(myVariable).to.deep.equal({ "foo": "bar" }); + }); + + it("should not mutate bound variable on failure", function() { + var expr = jsonata("$myVariable()"); + var myVariable = { "foo": "bar" }; + try { + expr.evaluate(testdata2, { myVariable }); + } catch (e) { + // ignore the evaluation error + } + expect(myVariable).to.deep.equal({ "foo": "bar" }); + }); }); });