Skip to content

Commit

Permalink
(fix) Expression evaluator should use typeof not instanceof to detect…
Browse files Browse the repository at this point in the history
… functions (openmrs#1174)
  • Loading branch information
samuelmale authored and Samstar10 committed Oct 22, 2024
1 parent 7fbd81f commit 03c4540
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ describe('OpenMRS Expression Evaluator', () => {
).resolves.toBe(2);
});

it('Should support mock functions', () => {
expect(evaluate('api.getValue()', { api: { getValue: jest.fn().mockImplementation(() => 'value') } })).toBe(
'value',
);
});

it('Should support real-world use-cases', () => {
expect(
evaluate('!isEmpty(array)', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ function visitCallExpression(expression: jsep.CallExpression, context: Evaluatio

if (!callee) {
throw `No function named ${expression.callee} is defined in this context`;
} else if (!(callee instanceof Function)) {
} else if (!(typeof callee === 'function')) {
throw `${expression.callee} is not a function`;
}

Expand Down

0 comments on commit 03c4540

Please sign in to comment.