Skip to content

Commit 2508d20

Browse files
committed
feat(fields): do not pass NaN in FinF [CLK-656138]
If a formula is a variable to another formula, we can't use NaN to indicate the impossibility to calculate it (for example because of a missing variable value). In such cases, we must provide null to indicate missing value as with normal variables. Fix added and a test case for it.
1 parent 5d0adc3 commit 2508d20

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/clickup/clickupParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ export class ClickUpParser {
6666
if (error) {
6767
throw new Error(error);
6868
}
69+
70+
if (Number.isNaN(result)) {
71+
// this formula could not be calculated, but is used as a variable
72+
// for another formula. Formulas do not accept NaN, so we need to
73+
// map this to null
74+
return null;
75+
}
6976
return result;
7077
}
7178

test/unit/clickup/clickupParser.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ describe('ClickUpParser', () => {
2929
expect(result).toEqual({ error: null, result: 110 });
3030
});
3131

32+
it('should handle empty variables in internal formulas', () => {
33+
const parser = ClickUpParser.create();
34+
// empty variable
35+
parser.setVariable(CF_1, null);
36+
// formula using empty variable
37+
// this formula would normally return NaN, but called from a formula
38+
// we need to return null or we get #VALUE! error
39+
parser.setVariable(CF_2, `${CF_1} * 2`, true);
40+
// set variable
41+
parser.setVariable(CF_3, 50);
42+
// formula using set variable and a formula using empty variable
43+
const formula = `${CF_3} - ${CF_2}`;
44+
const result = parser.parse(formula);
45+
expect(result).toEqual({ error: null, result: Number.NaN });
46+
});
47+
3248
it('should return error if formula variable is invalid', () => {
3349
const parser = ClickUpParser.create();
3450
parser.setVariable(CF_1, '100/0', true);

0 commit comments

Comments
 (0)