Skip to content

Commit 8bece2d

Browse files
travistlane-formio
authored andcommitted
Writing a test for the evaluator.
1 parent 8358567 commit 8bece2d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/utils/__tests__/Evaluator.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,4 +228,25 @@ describe('Evaluator', function () {
228228
'<span>Sun, 02 May 2021 21:00:00 GMT</span>',
229229
);
230230
});
231+
232+
it('Should treat undefined variable as true in custom conditional evaluation', function () {
233+
// Simulate the checkCustomConditional logic
234+
const context = { data: {}, form: {}, paths: {}, local: {} };
235+
// Script does not set 'show', so result should be true
236+
assert.equal(Evaluator.evaluate('if (false) { show = false; }', context, 'show'), undefined);
237+
// The checkCustomConditional logic would treat undefined as true
238+
// So, simulate that logic here
239+
const value = Evaluator.evaluate('if (false) { show = false; }', context, 'show');
240+
assert.equal(value === undefined ? true : value, true);
241+
242+
// Script sets show = false
243+
assert.equal(Evaluator.evaluate('show = false;', context, 'show'), false);
244+
const value2 = Evaluator.evaluate('show = false;', context, 'show');
245+
assert.equal(value2 === undefined ? true : value2, false);
246+
247+
// Script sets show = true
248+
assert.equal(Evaluator.evaluate('show = true;', context, 'show'), true);
249+
const value3 = Evaluator.evaluate('show = true;', context, 'show');
250+
assert.equal(value3 === undefined ? true : value3, true);
251+
});
231252
});

0 commit comments

Comments
 (0)