Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/clickup/clickupParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export class ClickUpParser {
if (error) {
throw new Error(error);
}

if (Number.isNaN(result)) {
// this formula could not be calculated, but is used as a variable
// for another formula. Formulas do not accept NaN, so we need to
// map this to null
return null;
}
return result;
}

Expand Down
16 changes: 16 additions & 0 deletions test/unit/clickup/clickupParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ describe('ClickUpParser', () => {
expect(result).toEqual({ error: null, result: 110 });
});

it('should handle empty variables in internal formulas', () => {
const parser = ClickUpParser.create();
// empty variable
parser.setVariable(CF_1, null);
// formula using empty variable
// this formula would normally return NaN, but called from a formula
// we need to return null or we get #VALUE! error
parser.setVariable(CF_2, `${CF_1} * 2`, true);
// set variable
parser.setVariable(CF_3, 50);
// formula using set variable and a formula using empty variable
const formula = `${CF_3} - ${CF_2}`;
const result = parser.parse(formula);
expect(result).toEqual({ error: null, result: Number.NaN });
});

it('should return error if formula variable is invalid', () => {
const parser = ClickUpParser.create();
parser.setVariable(CF_1, '100/0', true);
Expand Down