We are running into unexpected behaviour with a user while trying to author a simple TypeScript function.
A minimal repro looks something like this:
@Function()
public testFunction(): Long {
const existingObjects = Objects.search()
.myTestObject()
.all();
return existingObjects.length;
}
The return type of .all()
should be MyTestObject[]
, so we expect this function to always return a number, either 0 or whatever number of objects we have access to.
In live preview, this function works and returns e.g. “6”. However, in the unit tests in this same repo, we are for some reason getting “undefined” back from the search, and tests fail with this error:
TypeError: Cannot read properties of undefined (reading 'length')
9 | .all();
10 |
> 11 | return existingObjects.length;
| ^
12 | }
13 | }
14 |
Why is this happening? Shouldn’t the result be “0”, or some other number?